Skip to content
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

Add support for pedestrian position #598

Merged
merged 6 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion custom_components/tahoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR
from homeassistant.components.number import DOMAIN as NUMBER
from homeassistant.components.scene import DOMAIN as SCENE
from homeassistant.components.select import DOMAIN as SELECT
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.components.switch import DOMAIN as SWITCH
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
Expand Down Expand Up @@ -180,9 +181,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
platforms = defaultdict(list)

# Sensor and Binary Sensor will be added dynamically, based on the device states
# Select will be added dynamically, based on device features (e.g. DiscreteGateWithPedestrianPosition)
# Switch will be added dynamically, based on device features (e.g. low speed cover switch)
# Number will be added dynamically, based on device features (e.g. My position)
default_platforms = [BINARY_SENSOR, SENSOR, SWITCH, NUMBER]
default_platforms = [BINARY_SENSOR, SELECT, SENSOR, SWITCH, NUMBER]

for platform in default_platforms:
platforms[platform] = []
Expand Down
72 changes: 72 additions & 0 deletions custom_components/tahoma/select.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Support for Overkiz select devices."""
from homeassistant.components.cover import DOMAIN as COVER
from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from custom_components.tahoma.coordinator import OverkizDataUpdateCoordinator
from custom_components.tahoma.cover_devices.tahoma_cover import (
COMMAND_CLOSE,
COMMAND_OPEN,
)

from .const import DOMAIN
from .entity import OverkizEntity

CORE_OPEN_CLOSED_PEDESTRIAN_STATE = "core:OpenClosedPedestrianState"
COMMAND_SET_PEDESTRIAN_POSITION = "setPedestrianPosition"

OPTION_TO_COMMAND = {
"closed": COMMAND_CLOSE,
"open": COMMAND_OPEN,
"pedestrian": COMMAND_SET_PEDESTRIAN_POSITION,
}


async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up the Overkiz select from a config entry."""
data = hass.data[DOMAIN][entry.entry_id]
coordinator = data["coordinator"]

entities = [
PedestrianGateSelect(device.deviceurl, coordinator)
for device in data["platforms"][COVER]
if CORE_OPEN_CLOSED_PEDESTRIAN_STATE in device.states
]

async_add_entities(entities)


class PedestrianGateSelect(OverkizEntity, SelectEntity):
"""Representation of the various state for a pedestrian gate."""

_attr_icon = "mdi:content-save-cog"

def __init__(
self,
device_url: str,
coordinator: OverkizDataUpdateCoordinator,
):
"""Initialize the device."""
super().__init__(device_url, coordinator)
self._attr_name = f"{super().name} Position"

@property
def current_option(self):
"""Return the selected entity option to represent the entity state."""
return self.device.states.get(CORE_OPEN_CLOSED_PEDESTRIAN_STATE).value

@property
def options(self):
"""Return a set of selectable options."""
return ["closed", "open", "pedestrian"]

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
if option in OPTION_TO_COMMAND:
await self.executor.async_execute_command(OPTION_TO_COMMAND[option])