-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Add Nuki battery percentage sensor #84968
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
Merged
+50
−1
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e133813
Nuki: add battery percentage + add to device registry
Savjee 2a3dcf5
Remove unused import
Savjee 0e64324
Fixing linting and sorting issues
Savjee c579218
Update homeassistant/components/nuki/sensor.py
Savjee f52008f
Shorthand for adding entities
Savjee f77e64c
Use _attr_has_entity_name for battery sensor
Savjee 49a4fb1
Fix linting issue
Savjee b031213
Remove device registry changes
Savjee a7efbe9
Exclude from coverage
Savjee c2ce5e4
Use _attr_ instead of properties
Savjee 1f38e1b
Clean up
MartinHjelmare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Battery sensor for the Nuki Lock.""" | ||
|
|
||
| from homeassistant.components.sensor import SensorDeviceClass, SensorEntity | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import PERCENTAGE | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity import EntityCategory | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from . import NukiEntity | ||
| from .const import ATTR_NUKI_ID, DATA_COORDINATOR, DATA_LOCKS, DOMAIN as NUKI_DOMAIN | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
| ) -> None: | ||
| """Set up the Nuki lock sensor.""" | ||
| data = hass.data[NUKI_DOMAIN][entry.entry_id] | ||
| coordinator = data[DATA_COORDINATOR] | ||
|
|
||
| async_add_entities( | ||
| [NukiBatterySensor(coordinator, lock) for lock in data[DATA_LOCKS]] | ||
| ) | ||
|
|
||
|
|
||
| class NukiBatterySensor(NukiEntity, SensorEntity): | ||
| """Representation of a Nuki Lock Battery sensor.""" | ||
|
|
||
| _attr_has_entity_name = True | ||
|
|
||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
| _attr_name = "Battery" | ||
| _attr_native_unit_of_measurement = PERCENTAGE | ||
| _attr_device_class = SensorDeviceClass.BATTERY | ||
| _attr_entity_category = EntityCategory.DIAGNOSTIC | ||
|
|
||
| @property | ||
| def unique_id(self) -> str: | ||
| """Return a unique ID.""" | ||
| return f"{self._nuki_device.nuki_id}_battery_level" | ||
|
|
||
| @property | ||
| def extra_state_attributes(self): | ||
| """Return the device specific state attributes.""" | ||
| data = { | ||
| ATTR_NUKI_ID: self._nuki_device.nuki_id, | ||
| } | ||
| return data | ||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
|
|
||
| @property | ||
| def native_value(self) -> float: | ||
| """Return the state of the sensor.""" | ||
| return self._nuki_device.battery_charge | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.