Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last_reset attribute #22

Open
gtdiehl opened this issue Aug 27, 2021 · 6 comments
Open

Remove last_reset attribute #22

gtdiehl opened this issue Aug 27, 2021 · 6 comments

Comments

@gtdiehl
Copy link
Owner

gtdiehl commented Aug 27, 2021

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
Copy link
Contributor

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
Copy link
Owner Author

gtdiehl commented Sep 3, 2021

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
Copy link

OzGav commented Oct 9, 2021

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

@jyavenard
Copy link
Contributor

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
Copy link

OzGav commented Dec 17, 2021

Any updates?

@OzGav
Copy link

OzGav commented Dec 19, 2021

I have a suggested PR #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants