-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add raid array degraded state binary sensor to freebox sensors #95242
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
jbouwh
merged 1 commit into
home-assistant:dev
from
fthiery:freebox-raid-degraded-sensor
Jul 5, 2023
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Support for Freebox devices (Freebox v6 and Freebox mini 4K).""" | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| 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.dispatcher import async_dispatcher_connect | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from .const import DOMAIN | ||
| from .router import FreeboxRouter | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| RAID_SENSORS: tuple[BinarySensorEntityDescription, ...] = ( | ||
| BinarySensorEntityDescription( | ||
| key="raid_degraded", | ||
| name="degraded", | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
| ) -> None: | ||
| """Set up the binary sensors.""" | ||
| router: FreeboxRouter = hass.data[DOMAIN][entry.unique_id] | ||
|
|
||
| _LOGGER.debug("%s - %s - %s raid(s)", router.name, router.mac, len(router.raids)) | ||
|
|
||
| binary_entities = [ | ||
| FreeboxRaidDegradedSensor(router, raid, description) | ||
| for raid in router.raids.values() | ||
| for description in RAID_SENSORS | ||
| ] | ||
|
|
||
| if binary_entities: | ||
| async_add_entities(binary_entities, True) | ||
|
|
||
|
|
||
| class FreeboxRaidDegradedSensor(BinarySensorEntity): | ||
| """Representation of a Freebox raid sensor.""" | ||
|
|
||
| _attr_should_poll = False | ||
| _attr_has_entity_name = True | ||
|
|
||
| def __init__( | ||
| self, | ||
| router: FreeboxRouter, | ||
| raid: dict[str, Any], | ||
| description: BinarySensorEntityDescription, | ||
| ) -> None: | ||
| """Initialize a Freebox raid degraded sensor.""" | ||
| self.entity_description = description | ||
| self._router = router | ||
| self._attr_device_info = router.device_info | ||
| self._raid = raid | ||
| self._attr_name = f"Raid array {raid['id']} {description.name}" | ||
| self._attr_unique_id = ( | ||
| f"{router.mac} {description.key} {raid['name']} {raid['id']}" | ||
| ) | ||
|
|
||
| @callback | ||
| def async_update_state(self) -> None: | ||
| """Update the Freebox Raid sensor.""" | ||
| self._raid = self._router.raids[self._raid["id"]] | ||
|
|
||
| @property | ||
| def is_on(self) -> bool: | ||
| """Return true if degraded.""" | ||
| return self._raid["degraded"] | ||
|
|
||
| @callback | ||
| def async_on_demand_update(self): | ||
| """Update state.""" | ||
| self.async_update_state() | ||
| self.async_write_ha_state() | ||
|
|
||
| async def async_added_to_hass(self) -> None: | ||
| """Register state update callback.""" | ||
| self.async_update_state() | ||
| self.async_on_remove( | ||
| async_dispatcher_connect( | ||
| self.hass, | ||
| self._router.signal_sensor_update, | ||
| self.async_on_demand_update, | ||
| ) | ||
| ) | ||
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
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.