-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
279 additions
and
202 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,53 @@ | ||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS | ||
from homeassistant.components.device_tracker.config_entry import TrackerEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import ( | ||
COORDINATOR, | ||
DOMAIN, | ||
Platform, | ||
PlatformToPropertyType, | ||
) | ||
from .coordinator import EufySecurityDataUpdateCoordinator | ||
from .entity import EufySecurityEntity | ||
from .eufy_security_api.metadata import Metadata | ||
from .eufy_security_api.util import get_child_value | ||
from .util import get_product_properties_by_filter | ||
|
||
_LOGGER: logging.Logger = logging.getLogger(__package__) | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None: | ||
"""Setup switch entities.""" | ||
|
||
coordinator: EufySecurityDataUpdateCoordinator = hass.data[DOMAIN][COORDINATOR] | ||
product_properties = get_product_properties_by_filter( | ||
[coordinator.devices.values(), coordinator.stations.values()], PlatformToPropertyType[Platform.SWITCH.name].value | ||
) | ||
entities = [EufySwitchEntity(coordinator, metadata) for metadata in product_properties] | ||
async_add_entities(entities) | ||
|
||
|
||
class EufyDeviceTrackerEntity(TrackerEntity, EufySecurityEntity): | ||
"""Base switch entity for integration""" | ||
|
||
def __init__(self, coordinator: EufySecurityDataUpdateCoordinator, metadata: Metadata) -> None: | ||
super().__init__(coordinator, metadata) | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if the switch is on.""" | ||
return bool(get_child_value(self.product.properties, self.metadata.name)) | ||
|
||
async def async_turn_off(self, **kwargs: Any) -> None: | ||
"""Turn the entity off.""" | ||
await self.product.set_property(self.metadata, False) | ||
|
||
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Turn the entity on.""" | ||
await self.product.set_property(self.metadata, True) |
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
Oops, something went wrong.