-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from elad-bar/use-coordinator
Use coordinator
Showing
76 changed files
with
2,429 additions
and
4,063 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
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 |
---|---|---|
@@ -1,34 +1,61 @@ | ||
""" | ||
Support for binary sensors. | ||
""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from .core.components.binary_sensor import CoreBinarySensor | ||
from .core.helpers.setup_base_entry import async_setup_base_entry | ||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorEntity, | ||
BinarySensorEntityDescription, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import ATTR_ICON, Platform | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .common.base_entity import MyDolphinPlusBaseEntity, async_setup_entities | ||
from .common.consts import ATTR_ATTRIBUTES, ATTR_IS_ON | ||
from .common.entity_descriptions import MyDolphinPlusDailyBinarySensorEntityDescription | ||
from .managers.coordinator import MyDolphinPlusCoordinator | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
CURRENT_DOMAIN = Platform.SENSOR | ||
|
||
async def async_setup_entry(hass, config_entry, async_add_devices): | ||
"""Set up the component.""" | ||
await async_setup_base_entry( | ||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities | ||
): | ||
await async_setup_entities( | ||
hass, | ||
config_entry, | ||
async_add_devices, | ||
CoreBinarySensor.get_domain(), | ||
CoreBinarySensor.get_component, | ||
entry, | ||
CURRENT_DOMAIN, | ||
BinarySensorEntityDescription, | ||
MyDolphinPlusBinarySensorEntity, | ||
async_add_entities, | ||
) | ||
|
||
|
||
async def async_unload_entry(hass, config_entry): | ||
_LOGGER.info( | ||
f"Unload entry for {CoreBinarySensor.get_domain()} domain: {config_entry}" | ||
) | ||
class MyDolphinPlusBinarySensorEntity(MyDolphinPlusBaseEntity, BinarySensorEntity): | ||
"""Representation of a sensor.""" | ||
|
||
def __init__( | ||
self, | ||
entity_description: BinarySensorEntityDescription | ||
| MyDolphinPlusDailyBinarySensorEntityDescription, | ||
coordinator: MyDolphinPlusCoordinator, | ||
): | ||
super().__init__(entity_description, coordinator, CURRENT_DOMAIN) | ||
|
||
self._attr_device_class = entity_description.device_class | ||
|
||
def update_component(self, data): | ||
"""Fetch new state parameters for the sensor.""" | ||
if data is not None: | ||
is_on = data.get(ATTR_IS_ON) | ||
attributes = data.get(ATTR_ATTRIBUTES) | ||
icon = data.get(ATTR_ICON) | ||
|
||
return True | ||
self._attr_is_on = is_on | ||
self._attr_extra_state_attributes = attributes | ||
|
||
if icon is not None: | ||
self._attr_icon = icon | ||
|
||
async def async_remove_entry(hass, entry) -> None: | ||
_LOGGER.info(f"Remove entry for {CoreBinarySensor.get_domain()} entry: {entry}") | ||
else: | ||
self._attr_is_on = None |
File renamed without changes.
Oops, something went wrong.