-
Notifications
You must be signed in to change notification settings - Fork 2
Scan updates #314
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
Scan updates #314
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ceb445a
add binary sensor to show the configuration has changed but the node …
dirixmjm 2d1333c
missing await
dirixmjm df195ad
binary_sensor cannot be inside CONFIG catagory
dirixmjm 5ff335e
set more sensible value ranges, remove assigned of parameter as the n…
dirixmjm 066e725
improve error notice on device unavailable
dirixmjm 618738c
no need to poll on start-up, prevents not-available messages
dirixmjm b080310
implement select function for MotionSensitivity
dirixmjm 206fcaa
make notification more verbose
dirixmjm 9a53c19
fix translations
dirixmjm e6ecf92
CF: remove space
dirixmjm ab3a215
CR: Recommendations on updates and imprt Enum
dirixmjm 6a06026
CR: Fix typo
dirixmjm 99b9b31
Add ping button
dirixmjm c2e189a
change translation keys according to CR whishes
dirixmjm 260fc50
button cannot be inside diagnostics for some reason
dirixmjm 5655877
fix lowercase keys in translations, which is required according to ha…
dirixmjm 8d1ac07
CR: improve exception
dirixmjm 2683340
Link to plugwise_usb v0.44.12
bouwew 9264fa3
Ruff updates
bouwew 4e09652
Coordinator: add space in logging-message
bouwew f0d780b
Sorting, cleanup
bouwew f9ed3b3
Use _attr_options, then no property required
bouwew 12dd8d5
Use _attr_current_option as well
bouwew 9520f96
Remove api_attribute, same as key
bouwew 6bf585e
Bump version to v0.55.9(a0)
bouwew 4d835f3
CR: fix node_duc reference
dirixmjm 49bbea1
CR: nitpick typo
dirixmjm 3db9f5a
CR: move options to options_enum
dirixmjm 477b64e
fix type
dirixmjm 0195b7e
bouwew: fixes to select.py
dirixmjm 9802ab2
version bump
dirixmjm ca6f969
change to lowercase
dirixmjm 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
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
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,139 @@ | ||
| """Plugwise USB Select component for HomeAssistant.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from plugwise_usb.api import MotionSensitivity, NodeEvent, NodeFeature | ||
|
|
||
| from homeassistant.components.select import SelectEntity, SelectEntityDescription | ||
| from homeassistant.const import EntityCategory, Platform | ||
| from homeassistant.core import HomeAssistant, callback | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from .const import NODES, STICK, UNSUB_NODE_LOADED | ||
| from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator | ||
| from .entity import PlugwiseUSBEntity, PlugwiseUSBEntityDescription | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| PARALLEL_UPDATES = 2 | ||
| SCAN_INTERVAL = timedelta(seconds=30) | ||
|
|
||
|
|
||
| @dataclass(kw_only=True) | ||
| class PlugwiseSelectEntityDescription( | ||
| PlugwiseUSBEntityDescription, SelectEntityDescription | ||
| ): | ||
| """Describes Plugwise select entity.""" | ||
|
|
||
| async_select_fn: str = "" | ||
|
|
||
|
|
||
| SELECT_TYPES: tuple[PlugwiseSelectEntityDescription, ...] = ( | ||
| PlugwiseSelectEntityDescription( | ||
| key="sensitivity_level", | ||
| translation_key="motion_sensitivity_level", | ||
| async_select_fn="set_motion_sensitivity_level", | ||
| entity_category=EntityCategory.CONFIG, | ||
| node_feature=NodeFeature.MOTION_CONFIG, | ||
| options = MotionSensitivity, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| _hass: HomeAssistant, | ||
| config_entry: PlugwiseUSBConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set up the USB selectes from a config entry.""" | ||
|
|
||
| async def async_add_select(node_event: NodeEvent, mac: str) -> None: | ||
| """Initialize DUC for select.""" | ||
| if node_event != NodeEvent.LOADED: | ||
| return | ||
| entities: list[PlugwiseUSBEntity] = [] | ||
| if (node_duc := config_entry.runtime_data[NODES].get(mac)) is not None: | ||
| _LOGGER.debug( | ||
| "Add select entities for %s | duc=%s", mac, node_duc.node.name | ||
| ) | ||
| entities.extend( | ||
| [ | ||
| PlugwiseUSBSelectEntity(node_duc, entity_description) | ||
| for entity_description in SELECT_TYPES | ||
| if entity_description.node_feature in node_duc.node.features | ||
| ] | ||
dirixmjm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| if entities: | ||
| async_add_entities(entities) | ||
|
|
||
| api_stick = config_entry.runtime_data[STICK] | ||
|
|
||
| # Listen for loaded nodes | ||
| config_entry.runtime_data[Platform.SELECT] = {} | ||
| config_entry.runtime_data[Platform.SELECT][UNSUB_NODE_LOADED] = ( | ||
| api_stick.subscribe_to_node_events( | ||
| async_add_select, | ||
| (NodeEvent.LOADED,), | ||
| ) | ||
| ) | ||
|
|
||
| # load any current nodes | ||
| for mac, node in api_stick.nodes.items(): | ||
| if node.is_loaded: | ||
| await async_add_select(NodeEvent.LOADED, mac) | ||
|
|
||
|
|
||
| async def async_unload_entry( | ||
| _hass: HomeAssistant, | ||
| config_entry: PlugwiseUSBConfigEntry, | ||
| ) -> None: | ||
| """Unload a config entry.""" | ||
| config_entry.runtime_data[Platform.SELECT][UNSUB_NODE_LOADED]() | ||
|
|
||
|
|
||
| class PlugwiseUSBSelectEntity(PlugwiseUSBEntity, SelectEntity): | ||
| """Representation of a Plugwise USB Data Update Coordinator select.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| node_duc: PlugwiseUSBDataUpdateCoordinator, | ||
| entity_description: PlugwiseSelectEntityDescription, | ||
| ) -> None: | ||
| """Initialize a select entity.""" | ||
| super().__init__(node_duc, entity_description) | ||
| self.async_select_fn = getattr( | ||
| node_duc.node, entity_description.async_select_fn | ||
| ) | ||
| self._attr_options: list[str] = [o.name.lower() for o in entity_description.options] | ||
| self.entity_description = entity_description | ||
| self._node_duc = node_duc | ||
|
|
||
| @callback | ||
| def _handle_coordinator_update(self) -> None: | ||
| """Handle updated data from the coordinator.""" | ||
| data = self.coordinator.data.get(self.entity_description.node_feature, None) | ||
| if data is None: | ||
| _LOGGER.debug( | ||
| "No %s select data for %s", | ||
| str(self.entity_description.node_feature), | ||
| self._node_info.mac, | ||
| ) | ||
| return | ||
|
|
||
| current_option = getattr( | ||
| data, | ||
| self.entity_description.key, | ||
| ) | ||
| self._attr_current_option = current_option.name.lower() | ||
| self.async_write_ha_state() | ||
|
|
||
| async def async_select_option(self, option: str) -> None: | ||
| """Change to the selected entity option.""" | ||
| value = self.entity_description.options[option.upper()] | ||
| await self.async_select_fn(value) | ||
| self._current_option = option | ||
| self._attr_current_option = option | ||
| self.async_write_ha_state() | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.