-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add Airzone Cloud Binary Sensors support #93583
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
gjohansson-ST
merged 15 commits into
home-assistant:dev
from
Noltari:airzone-cloud-binary-sensors
Jun 23, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a84adc7
airzone_cloud: add Binary Sensors support
Noltari a63e4b0
airzone_cloud: binary_sensor: fix copy&paste
Noltari b059209
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari afb8f03
airzone_cloud: remote available attribute
Noltari 83f8c25
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari 3266777
airzone_cloud: binary_sensor: remove unique_id
Noltari 965b3d2
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari dae6676
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari 50b8d54
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari 704e922
airzone_cloud: binary_sensors: remove name
Noltari 7b6adc0
airzone_cloud: use entity_name
Noltari db68d05
airzone_cloud: binary_sensor: add name=None
Noltari 73ed255
airzone_cloud: binary_sensor: fix device class name
Noltari ddb886f
Merge remote-tracking branch 'upstream/dev' into airzone-cloud-binary…
Noltari 164dd69
Update homeassistant/components/airzone_cloud/binary_sensor.py
Noltari 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
108 changes: 108 additions & 0 deletions
108
homeassistant/components/airzone_cloud/binary_sensor.py
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,108 @@ | ||
| """Support for the Airzone Cloud binary sensors.""" | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any, Final | ||
|
|
||
| from aioairzone_cloud.const import AZD_PROBLEMS, AZD_WARNINGS, AZD_ZONES | ||
|
|
||
| from homeassistant.components.binary_sensor import ( | ||
| BinarySensorDeviceClass, | ||
| BinarySensorEntity, | ||
| BinarySensorEntityDescription, | ||
| ) | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import EntityCategory | ||
| from homeassistant.core import HomeAssistant, callback | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from .const import DOMAIN | ||
| from .coordinator import AirzoneUpdateCoordinator | ||
| from .entity import AirzoneEntity, AirzoneZoneEntity | ||
|
|
||
|
|
||
| @dataclass | ||
| class AirzoneBinarySensorEntityDescription(BinarySensorEntityDescription): | ||
| """A class that describes Airzone Cloud binary sensor entities.""" | ||
|
|
||
| attributes: dict[str, str] | None = None | ||
|
|
||
|
|
||
| ZONE_BINARY_SENSOR_TYPES: Final[tuple[AirzoneBinarySensorEntityDescription, ...]] = ( | ||
| AirzoneBinarySensorEntityDescription( | ||
| attributes={ | ||
| "warnings": AZD_WARNINGS, | ||
| }, | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| key=AZD_PROBLEMS, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
| ) -> None: | ||
| """Add Airzone Cloud binary sensors from a config_entry.""" | ||
| coordinator: AirzoneUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
|
|
||
| binary_sensors: list[AirzoneBinarySensor] = [] | ||
|
|
||
| for zone_id, zone_data in coordinator.data.get(AZD_ZONES, {}).items(): | ||
| for description in ZONE_BINARY_SENSOR_TYPES: | ||
| if description.key in zone_data: | ||
| binary_sensors.append( | ||
| AirzoneZoneBinarySensor( | ||
| coordinator, | ||
| description, | ||
| entry, | ||
| zone_id, | ||
| zone_data, | ||
| ) | ||
| ) | ||
|
|
||
| async_add_entities(binary_sensors) | ||
|
|
||
|
|
||
| class AirzoneBinarySensor(AirzoneEntity, BinarySensorEntity): | ||
| """Define an Airzone Cloud binary sensor.""" | ||
|
|
||
| entity_description: AirzoneBinarySensorEntityDescription | ||
|
|
||
| @callback | ||
| def _handle_coordinator_update(self) -> None: | ||
| """Update attributes when the coordinator updates.""" | ||
| self._async_update_attrs() | ||
| super()._handle_coordinator_update() | ||
|
|
||
| @callback | ||
| def _async_update_attrs(self) -> None: | ||
| """Update binary sensor attributes.""" | ||
| self._attr_is_on = self.get_airzone_value(self.entity_description.key) | ||
| if self.entity_description.attributes: | ||
| self._attr_extra_state_attributes = { | ||
| key: self.get_airzone_value(val) | ||
| for key, val in self.entity_description.attributes.items() | ||
| } | ||
|
gjohansson-ST marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class AirzoneZoneBinarySensor(AirzoneZoneEntity, AirzoneBinarySensor): | ||
| """Define an Airzone Cloud Zone binary sensor.""" | ||
|
|
||
|
Noltari marked this conversation as resolved.
|
||
| _attr_has_entity_name = True | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: AirzoneUpdateCoordinator, | ||
| description: AirzoneBinarySensorEntityDescription, | ||
| entry: ConfigEntry, | ||
| zone_id: str, | ||
| zone_data: dict[str, Any], | ||
| ) -> None: | ||
| """Initialize.""" | ||
| super().__init__(coordinator, entry, zone_id, zone_data) | ||
|
|
||
| self._attr_unique_id = f"{zone_id}_{description.key}" | ||
| self.entity_description = description | ||
|
|
||
| self._async_update_attrs() | ||
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,21 @@ | ||
| """The binary sensor tests for the Airzone Cloud platform.""" | ||
|
|
||
| from homeassistant.const import STATE_OFF | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from .util import async_init_integration | ||
|
|
||
|
|
||
| async def test_airzone_create_binary_sensors(hass: HomeAssistant) -> None: | ||
| """Test creation of binary sensors.""" | ||
|
|
||
| await async_init_integration(hass) | ||
|
|
||
| # Zones | ||
| state = hass.states.get("binary_sensor.dormitorio_problem") | ||
| assert state.state == STATE_OFF | ||
| assert state.attributes.get("warnings") is None | ||
|
|
||
| state = hass.states.get("binary_sensor.salon_problem") | ||
| assert state.state == STATE_OFF | ||
| assert state.attributes.get("warnings") is None |
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.