Skip to content

Commit

Permalink
Always add attribution to sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
mjj4791 committed Sep 7, 2024
1 parent 2a8feda commit 1e305b5
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions homeassistant/components/buienradar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,16 @@ def _load_data(self, data): # noqa: C901
self._measured = data.get(MEASURED)
sensor_type = self.entity_description.key

extra_state_attributes = {
ATTR_ATTRIBUTION: data.get(ATTRIBUTION),
STATIONNAME_LABEL: data.get(STATIONNAME),
}
if self._measured is not None:
# convert datetime (Europe/Amsterdam) into local datetime
local_dt = dt_util.as_local(self._measured)
extra_state_attributes[MEASURED_LABEL] = local_dt.strftime("%c")
self._attr_extra_state_attributes = extra_state_attributes

if sensor_type.endswith(("_1d", "_2d", "_3d", "_4d", "_5d")):
# update forecasting sensors:
fcday = 0
Expand Down Expand Up @@ -867,6 +877,11 @@ def _load_data(self, data): # noqa: C901
self._attr_native_value = nested.get(
sensor_type[len(PRECIPITATION_FORECAST) + 1 :]
)

if self._timeframe is not None:
extra_state_attributes[TIMEFRAME_LABEL] = "%d min" % (self._timeframe)
self._attr_extra_state_attributes = extra_state_attributes

return True

if sensor_type in [WINDSPEED, WINDGUST]:
Expand All @@ -885,21 +900,5 @@ def _load_data(self, data): # noqa: C901

# update all other sensors
self._attr_native_value = data.get(sensor_type)
if sensor_type.startswith(PRECIPITATION_FORECAST):
result = {ATTR_ATTRIBUTION: data.get(ATTRIBUTION)}
if self._timeframe is not None:
result[TIMEFRAME_LABEL] = "%d min" % (self._timeframe)

self._attr_extra_state_attributes = result

result = {
ATTR_ATTRIBUTION: data.get(ATTRIBUTION),
STATIONNAME_LABEL: data.get(STATIONNAME),
}
if self._measured is not None:
# convert datetime (Europe/Amsterdam) into local datetime
local_dt = dt_util.as_local(self._measured)
result[MEASURED_LABEL] = local_dt.strftime("%c")

self._attr_extra_state_attributes = result
return True

0 comments on commit 1e305b5

Please sign in to comment.