gtdiehl / iotawatt_ha

IoTaWatt for Home Assistant
Apache License 2.0
16 stars 16 forks source link

Remove last_reset attribute #22

Open gtdiehl opened 3 years ago

gtdiehl commented 3 years ago

Starting in Home Assistant Core 2021.11 the last_attribute will be deprecated. Need to remove this attribute to avoid users seeing the below message for each entity that is using the attribute.

2021-08-27 21:57:49 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.iotawatt_output_subpaneltotal_wh (<class 'homeassistant.components.iotawatt.sensor.IotaWattSensor'>) with state_class measurement has set last_reset. Setting last_reset is deprecated and will be unsupported from Home Assistant Core 2021.11. Please update your configuration if state_class is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+iotawatt%22

jyavenard commented 3 years ago

Note that this warning will not show if last_reset returns None for the measurements sensor.

The pull request I've pushed for updating for 2021.9 will not show this warning, even though last_reset still exists.

fairly sure it will be re-added.

gtdiehl commented 3 years ago

I missed this during the code review! 🥲 Is this still needed in sensor.py? I don't see a need for it as this code is has a minimum HA version of 2021.9.0 and the last_reset property is not needed for that HA version.

    @property
    def last_reset(self):
       """Return the time when the sensor was last reset, if any."""
       if self.state_class == STATE_CLASS_MEASUREMENT:
           return None

       if self._accumulating:
           return datetime.min  # an accumulating sensor never reset.
       last_reset = self._sensor_data.getBegin()
       if last_reset is None:
           return None
       return dt.parse_datetime(last_reset)
OzGav commented 2 years ago

Note that this has been reintroduced and is to be used with state class TOTAL. I believe the sensors should be changed to state class TOTAL to fix this issue https://github.com/gtdiehl/iotawatt_ha/issues/33

jyavenard commented 2 years ago

Note that this has been reintroduced and is to be used with state class TOTAL. I believe the sensors should be changed to state class TOTAL to fix this issue #33

I have already pushed a change and landed the code in HA upstream.

I will backport those changes here

OzGav commented 2 years ago

Any updates?

OzGav commented 2 years ago

I have a suggested PR https://github.com/gtdiehl/iotawatt_ha/pull/37