-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
b817dcd
commit c7b39e0
Showing
10 changed files
with
316 additions
and
22 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,73 @@ | ||
"""Button for Unfolded Circle""" | ||
from typing import Any | ||
import logging | ||
|
||
from homeassistant.components.button import ButtonEntity, ButtonDeviceClass | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.const import EntityCategory | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
remote = hass.data[DOMAIN][config_entry.entry_id] | ||
|
||
# Verify that passed in configuration works | ||
if not await remote.can_connect(): | ||
_LOGGER.error("Could not connect to Remote") | ||
return | ||
|
||
# Get Basic Device Information | ||
await remote.update() | ||
|
||
new_devices = [] | ||
new_devices.append(Button(remote)) | ||
if new_devices: | ||
async_add_entities(new_devices) | ||
|
||
|
||
class Button(ButtonEntity): | ||
"""Representation of a Button entity.""" | ||
|
||
_attr_entity_category = EntityCategory.CONFIG | ||
_attr_icon = "mdi:gesture-tap-button" | ||
_attr_device_class = ButtonDeviceClass.RESTART | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
"""Return the device info.""" | ||
return DeviceInfo( | ||
identifiers={ | ||
# Serial numbers are unique identifiers within a specific domain | ||
(DOMAIN, self._remote.serial_number) | ||
}, | ||
name=self._remote.name, | ||
manufacturer=self._remote.manufacturer, | ||
model=self._remote.model_name, | ||
sw_version=self._remote.sw_version, | ||
hw_version=self._remote.hw_revision, | ||
configuration_url=self._remote.configuration_url, | ||
) | ||
|
||
def __init__(self, remote): | ||
"""Initialize the sensor.""" | ||
self._remote = remote | ||
self._attr_unique_id = f"{self._remote.serial_number}_restart_button" | ||
self._attr_name = f"{self._remote.name} Restart Remote" | ||
|
||
@property | ||
def available(self) -> bool: | ||
"""Return if entity is available.""" | ||
return self._remote._online | ||
|
||
async def async_press(self) -> None: | ||
"""Press the button.""" | ||
await self._remote.post_system_command("RESTART") |
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,98 @@ | ||
"""Remote sensor platform for Unfolded Circle""" | ||
from typing import Any | ||
import logging | ||
|
||
from homeassistant.components.remote import RemoteEntity, RemoteEntityFeature, RemoteEntityDescription | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
from homeassistant.helpers.entity import ToggleEntityDescription | ||
from homeassistant.helpers.device_registry import DeviceInfo | ||
from collections.abc import Iterable | ||
from .const import DOMAIN | ||
|
||
from homeassistant.const import ( | ||
ATTR_BATTERY_CHARGING, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
remote = hass.data[DOMAIN][config_entry.entry_id] | ||
|
||
# Verify that passed in configuration works | ||
if not await remote.can_connect(): | ||
_LOGGER.error("Could not connect to Remote") | ||
return | ||
|
||
# Get Basic Device Information | ||
await remote.update() | ||
await remote.get_remotes() | ||
await remote.get_remote_codesets() | ||
await remote.get_docks() | ||
|
||
new_devices = [] | ||
new_devices.append(RemoteSensor(remote)) | ||
if new_devices: | ||
async_add_entities(new_devices) | ||
|
||
|
||
class RemoteSensor(RemoteEntity): | ||
# The class of this device. Note the value should come from the homeassistant.const | ||
# module. More information on the available devices classes can be seen here: | ||
# https://developers.home-assistant.io/docs/core/entity/sensor | ||
_attr_icon = "mdi:remote" | ||
entity_description: ToggleEntityDescription | ||
_attr_supported_features: RemoteEntityFeature = RemoteEntityFeature.ACTIVITY | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
"""Return the device info.""" | ||
return DeviceInfo( | ||
identifiers={ | ||
# Serial numbers are unique identifiers within a specific domain | ||
(DOMAIN, self._remote.serial_number) | ||
}, | ||
name=self._remote.name, | ||
manufacturer=self._remote.manufacturer, | ||
model=self._remote.model_name, | ||
sw_version=self._remote.sw_version, | ||
hw_version=self._remote.hw_revision, | ||
configuration_url=self._remote.configuration_url, | ||
) | ||
|
||
def __init__(self, remote): | ||
"""Initialize the sensor.""" | ||
self._remote = remote | ||
|
||
# As per the sensor, this must be a unique value within this domain. This is done | ||
# by using the device ID, and appending "_battery" | ||
self._attr_unique_id = f"{self._remote.serial_number}_remote" | ||
|
||
# The name of the entity | ||
self._attr_name = f"{self._remote.name} Remote" | ||
self._attr_activity_list = [] | ||
self._attr_is_on = False | ||
for activity in self._remote.activities: | ||
self._attr_activity_list.append(activity.name) | ||
|
||
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Turn the entity on.""" | ||
self._attr_is_on = True | ||
|
||
async def async_turn_off(self, **kwargs: Any) -> None: | ||
"""Turn the entity off.""" | ||
self._attr_is_on = False | ||
|
||
async def async_send_command(self, command: Iterable[str], **kwargs): | ||
for indv_command in command: | ||
await self._remote.send_remote_command( | ||
device=kwargs.get("device"), | ||
command=indv_command, | ||
repeat=kwargs.get("num_repeats"), | ||
) |
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.