-
-
Notifications
You must be signed in to change notification settings - Fork 38.1k
Add number entity to Overkiz integration #62732
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94ee9bf
Address late feedback
iMicknl 7766762
Add number entity
iMicknl 72c1d4b
Add number entity to const
iMicknl 91daacf
Override type hint
iMicknl ebd139f
Exclude from codecoverage
iMicknl 5d6ca57
Revert "Address late feedback"
iMicknl d8d7d3f
Address feedback
iMicknl 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| PLATFORMS: list[Platform] = [ | ||
| Platform.BUTTON, | ||
| Platform.LOCK, | ||
| Platform.NUMBER, | ||
| Platform.SENSOR, | ||
| ] | ||
|
|
||
|
|
||
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,103 @@ | ||
| """Support for Overkiz (virtual) numbers.""" | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from pyoverkiz.enums import OverkizCommand, OverkizState | ||
|
|
||
| from homeassistant.components.number import NumberEntity, NumberEntityDescription | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity import EntityCategory | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from . import HomeAssistantOverkizData | ||
| from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES | ||
| from .entity import OverkizDescriptiveEntity | ||
|
|
||
|
|
||
| @dataclass | ||
| class OverkizNumberDescriptionMixin: | ||
| """Define an entity description mixin for number entities.""" | ||
|
|
||
| command: str | ||
|
|
||
|
|
||
| @dataclass | ||
| class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin): | ||
| """Class to describe an Overkiz number.""" | ||
|
|
||
|
|
||
| NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [ | ||
| # Cover: My Position (0 - 100) | ||
| OverkizNumberDescription( | ||
| key=OverkizState.CORE_MEMORIZED_1_POSITION, | ||
| name="My Position", | ||
| icon="mdi:content-save-cog", | ||
| command=OverkizCommand.SET_MEMORIZED_1_POSITION, | ||
| entity_category=EntityCategory.CONFIG, | ||
| ), | ||
| # WaterHeater: Expected Number Of Shower (2 - 4) | ||
| OverkizNumberDescription( | ||
| key=OverkizState.CORE_EXPECTED_NUMBER_OF_SHOWER, | ||
| name="Expected Number Of Shower", | ||
| icon="mdi:shower-head", | ||
| command=OverkizCommand.SET_EXPECTED_NUMBER_OF_SHOWER, | ||
| min_value=2, | ||
| max_value=4, | ||
| entity_category=EntityCategory.CONFIG, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ): | ||
| """Set up the Overkiz number from a config entry.""" | ||
| data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] | ||
| entities: list[OverkizNumber] = [] | ||
|
|
||
| key_supported_states = { | ||
| description.key: description for description in NUMBER_DESCRIPTIONS | ||
| } | ||
|
|
||
| for device in data.coordinator.data.values(): | ||
| if ( | ||
| device.widget in IGNORED_OVERKIZ_DEVICES | ||
| or device.ui_class in IGNORED_OVERKIZ_DEVICES | ||
| ): | ||
| continue | ||
|
|
||
| for state in device.definition.states: | ||
| if description := key_supported_states.get(state.qualified_name): | ||
| entities.append( | ||
| OverkizNumber( | ||
| device.device_url, | ||
| data.coordinator, | ||
| description, | ||
| ) | ||
| ) | ||
|
|
||
| async_add_entities(entities) | ||
|
|
||
|
|
||
| class OverkizNumber(OverkizDescriptiveEntity, NumberEntity): | ||
| """Representation of an Overkiz Number.""" | ||
|
|
||
| entity_description: OverkizNumberDescription | ||
|
|
||
| @property | ||
| def value(self) -> float: | ||
| """Return the entity value to represent the entity state.""" | ||
| if state := self.device.states.get(self.entity_description.key): | ||
| return state.value | ||
|
|
||
| return 0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we default to 0 instead of None? |
||
|
|
||
| async def async_set_value(self, value: float) -> None: | ||
| """Set new value.""" | ||
| await self.executor.async_execute_command( | ||
| self.entity_description.command, value | ||
|
iMicknl marked this conversation as resolved.
|
||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return value typing.