-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sensors , buttons , device_tracker
- Loading branch information
Showing
9 changed files
with
199 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 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 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,36 @@ | ||
"""Button for Bbox router.""" | ||
import logging | ||
|
||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from bboxpy.exceptions import BboxException | ||
from .const import DOMAIN | ||
from .entity import BboxEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
BUTTON_RESTART: tuple[ButtonEntityDescription, ...] = ButtonEntityDescription( | ||
key="restart", name="Restart", icon="mdi:restart-alert" | ||
) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
) -> None: | ||
"""Set up sensor.""" | ||
coordinator = hass.data[DOMAIN][entry.entry_id] | ||
entities = [RestartButton(coordinator, BUTTON_RESTART)] | ||
async_add_entities(entities) | ||
|
||
|
||
class RestartButton(BboxEntity, ButtonEntity): | ||
"""Representation of a button for reboot router.""" | ||
|
||
async def async_press(self) -> None: | ||
"""Handle the button press.""" | ||
try: | ||
await self.coordinator.bbox.device.async_reboot() | ||
except BboxException as error: | ||
_LOGGER.error(error) |
This file contains 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 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 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 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,32 @@ | ||
"""Helpers for component.""" | ||
from __future__ import annotations | ||
from collections.abc import Callable | ||
from dataclasses import dataclass | ||
from homeassistant.helpers.typing import StateType | ||
from homeassistant.components.sensor import SensorEntityDescription | ||
from homeassistant.components.binary_sensor import BinarySensorEntityDescription | ||
|
||
|
||
@dataclass | ||
class BboxValueFnMixin: | ||
"""Mixin for Audi sensor.""" | ||
|
||
value_fn: Callable[..., StateType] | None = None | ||
|
||
|
||
@dataclass | ||
class BboxSensorDescription(BboxValueFnMixin, SensorEntityDescription): | ||
"""Describes a sensor.""" | ||
|
||
|
||
@dataclass | ||
class BboxBinarySensorDescription(BboxValueFnMixin, BinarySensorEntityDescription): | ||
"""Describes a sensor.""" | ||
|
||
|
||
def finditem(data, entity_description): | ||
if (keys := entity_description.key.split(".")) and isinstance(keys, list): | ||
for key in keys: | ||
if isinstance(data, dict): | ||
data = data.get(key) | ||
return data |
This file contains 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.