pnbruckner / ha-sun2

Home Assistant Sun2 Sensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2021.12b0 warnings

tomlut opened this issue · comments

Home Assistant 2021.12b0 reports a bunch of warnings for the Sun2 integration:

2021-12-04 13:04:42 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.sunrise (<class 'custom_components.sun2.sensor.Sun2PointInTimeSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-04 13:04:42 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.solar_noon (<class 'custom_components.sun2.sensor.Sun2PointInTimeSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-04 13:04:42 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.sunset (<class 'custom_components.sun2.sensor.Sun2PointInTimeSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-04 13:04:42 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.astronomical_dusk (<class 'custom_components.sun2.sensor.Sun2PointInTimeSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-04 13:04:42 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.max_elevation (<class 'custom_components.sun2.sensor.Sun2MaxElevationSensor'>) implements device_state_attributes. Please report it to the custom component author.

This appears to be a simple name change from device_state_attributes to extra_state_attributes.

I tried to fix this but it's more complicated than that. the yesterday today and tomorrow attributes are broken as well..

Yeah I submitted a PR for Brendan's BoM integration but this one confuses me.

I'm not seeing any errors for the BOM one

That's because it has been patched. bremor/bureau_of_meteorology#93

I have the same warning on 2021.12.4

Same warning for me on 2021.12.2.

In sensor.py I have changed line 106 from def device_state_attributes(self): to def extra_state_attributes(self): and this seems to have got rid of the warning. All the sensors that were producing the warning extended class Sun2Sensor.

The whole bit is:

    @property
    def extra_state_attributes(self):
        """Return device specific state attributes."""
        return self._device_state_attributes()

As far as I can tell this is all that is required. I'll put through a pull request.

I think I tried that but a bunch of stuff disappeared like the today tyesterday and tomorrow attributes. Are you sure you've got everything working correctly with your PR? I can't check for a few days

I have updated the PR to bump the version number.

@DavidFW1960 as far as I can see, yesterday, today and tomorrow are still there. I think the trick may have been that only the @property name needed updating, and in contrast the function def _device_state_attributes(self) can keep its name since it is only internally referenced (consequently line 108 still says return self._device_state_attributes()).

This is the first of these that I've done, I don't usually write Python or have any experience with PRs or writing for Home Assistant, so any extra eyes would be great.

yeah I screwed up and edited line 98 as well which I should not have done
But see also here:

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:549
First occurred: 3:29:08 PM (4 occurrences)
Last logged: 3:29:16 PM

Entity binary_sensor.above_horizon (<class 'custom_components.sun2.binary_sensor.Sun2ElevationSensor'>) implements device_state_attributes. Please report it to the custom component author.
Entity binary_sensor.sun_above_25 (<class 'custom_components.sun2.binary_sensor.Sun2ElevationSensor'>) implements device_state_attributes. Please report it to the custom component author.
Entity sensor.solar_elevation (<class 'custom_components.sun2.sensor.Sun2ElevationSensor'>) implements device_state_attributes. Please report it to the custom component author.

So I think binary_sensor.py needs changing as well

    @property
    def extra_state_attributes(self):
        """Return device specific state attributes."""
        return {ATTR_NEXT_CHANGE: self._next_change}

ok so all changes needed:
binary_sensor.py

-    def device_state_attributes(self):
+    def extra_state_attributes(self):
        """Return device specific state attributes."""
        return {ATTR_NEXT_CHANGE: self._next_change}

sensor.py

    @property
-    def device_state_attributes(self):
+    def extra_state_attributes(self):
        """Return device specific state attributes."""
        return self._device_state_attributes()

@ -313,7 +313,7 @@ class Sun2ElevationSensor(Sun2Sensor):
        self._next_change = None

    @property
 -   def device_state_attributes(self):
 +   def extra_state_attributes(self):
        """Return device specific state attributes."""
        return {ATTR_NEXT_CHANGE: self._next_change}

and the version in the manifest

OK I have tried all the changes in my installation and there are no error message. The pull request shows all needed changes now.

One thing: I don't seem to be able to get the elevation binary sensor to show on HA. I don't know if it's my YAML syntax that is wrong. I've never needed to use it previously, so I don't know if this is a new problem.

My syntax in configuration.yaml:

binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation

My config:

# Binary Sensor for sun op or down
binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation
      - elevation:
          above: 25
          name: Sun Above 25

image

and the other one
image

Ok, it was working, it's just I didn't realise that the default elevation binary sensor is just called above_horizon.

Looks like everything works ok.

Yeah seems fine. I use the 25 degree one for a lights automation. Works well. The changes seem fine here no more errors and everything works

Thanks for your help @DavidFW1960!

Hi all. As you may be aware, I haven't worked on HA for quite some time. (I'm still running 2021.3.3, and I don't even know how many releases have occurred since then, let alone all their ramifications.) It would seem this is a simple change, but since custom components can be used with old versions of HA (as in my case) I don't like to release changes that break backwards compatibility. Maybe it would make sense to keep the existing properties and add the new ones that simply reference the old ones. Maybe I'll try and work on that in the near future.

@tomlut @DavidFW1960 @kurankat @Santanachia @ultimateguy
Could any of you try the changes in PR #55? I tested them with my 2021.3.3 HA install, but I'd like to get some verification it fixes the problems you have observed before releasing. Thx!

seems good Phil.

I have updated to version 2.0.3 (via HACS) and there are no warnings in the logs.