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

Use _attr_native_value instead of _attr_state in sensor entity #626

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

natekspencer
Copy link
Contributor

The state property of a sensor entity is marked as final in Home Assistant code and should not be used for a sensor's state. Instead the recommendation is to use the native_value property. This switches the code to use _attr_native_value instead of _attr_state as well as some additional cleanup in the sensor.py file for readability.

See https://github.com/home-assistant/core/blob/dev/homeassistant/components/sensor/__init__.py#L538
and https://developers.home-assistant.io/docs/core/entity/sensor

Copy link
Owner

@JurajNyiri JurajNyiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Left some minor comments, once addressed I will test and merge

custom_components/tapo_control/sensor.py Outdated Show resolved Hide resolved
custom_components/tapo_control/sensor.py Outdated Show resolved Hide resolved
custom_components/tapo_control/sensor.py Outdated Show resolved Hide resolved
custom_components/tapo_control/sensor.py Outdated Show resolved Hide resolved
@natekspencer
Copy link
Contributor Author

@JurajNyiri any luck checking this out? My goal here is to get this approved first, then move on to making the HDD storage sensors appropriately represent numeric data with the DATA_SIZE device class and UnitOfInformation measurements.

@JurajNyiri
Copy link
Owner

Thank you for the reminder and PR, I was very busy lately. I will try to review and test this during the weekend.

@natekspencer
Copy link
Contributor Author

Thank you for the reminder and PR, I was very busy lately. I will try to review and test this during the weekend.

No worries, just didn't want it to get lost!

@JurajNyiri JurajNyiri changed the base branch from main to 5.6.1 August 12, 2024 21:21
@JurajNyiri JurajNyiri merged commit 09237f3 into JurajNyiri:5.6.1 Aug 12, 2024
@JurajNyiri
Copy link
Owner

Thank you! Merged

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.

2 participants