Skip to content

Use _attr_native_value#51

Merged
danieldotnl merged 1 commit intodanieldotnl:masterfrom
ludeeus:patch-1
Sep 1, 2021
Merged

Use _attr_native_value#51
danieldotnl merged 1 commit intodanieldotnl:masterfrom
ludeeus:patch-1

Conversation

@ludeeus
Copy link
Copy Markdown
Contributor

@ludeeus ludeeus commented Aug 16, 2021

Using _attr_state for SensorEntity is being removed in home-assistant/core#54624

Fixes Fixes #50

This will require Home Assistant Core 2021.9.0+

@danieldotnl
Copy link
Copy Markdown
Owner

Wow, courtesy of the HA team? 😄

@danieldotnl
Copy link
Copy Markdown
Owner

I'm currently on vacation but will merge and create a pre-release when 2021.9 is released.

@ludeeus
Copy link
Copy Markdown
Contributor Author

ludeeus commented Aug 16, 2021

You can do this to make it compatible with current/future versions:

from homeassistant.const import __version__ as HA_VERSION
from awesomeversion import AwesomeVersion

_USES_NATIVE_VALUE = AwesomeVersion(HA_VERSION) >= "2021.9.0"

...

if _USES_NATIVE_VALUE:
	self._attr_native_value = value
else:
	self._attr_state = value

@danieldotnl
Copy link
Copy Markdown
Owner

Tnx, but not on my phone 😄

@danieldotnl danieldotnl merged commit 16724e8 into danieldotnl:master Sep 1, 2021
@ludeeus ludeeus deleted the patch-1 branch September 1, 2021 20:38
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

Successfully merging this pull request may close these issues.

Need to update to handle breaking changes in Home Assistant 2021.9

2 participants