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

Backport siren #773

Merged
merged 1 commit into from
Feb 20, 2022
Merged
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
32 changes: 13 additions & 19 deletions custom_components/tahoma/siren.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for Overkiz sirens."""
from typing import Any

from pyoverkiz.enums import OverkizState
from pyoverkiz.enums.command import OverkizCommand, OverkizCommandParam

Expand All @@ -23,55 +25,47 @@ async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
) -> None:
"""Set up the Overkiz sirens from a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]

entities = [
async_add_entities(
OverkizSiren(device.device_url, data.coordinator)
for device in data.platforms[Platform.SIREN]
]

async_add_entities(entities)
)


class OverkizSiren(OverkizEntity, SirenEntity):
"""Representation an Overkiz Switch."""
"""Representation an Overkiz Siren."""

_attr_supported_features = SUPPORT_TURN_OFF | SUPPORT_TURN_ON | SUPPORT_DURATION

@property
def is_on(self):
def is_on(self) -> bool:
"""Get whether the siren is in on state."""
return (
self.executor.select_state(OverkizState.CORE_ON_OFF)
== OverkizCommandParam.ON
)

async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Send the on command."""

if kwargs.get(ATTR_DURATION):
duration = kwargs.get(ATTR_DURATION)
duration = kwargs[ATTR_DURATION]
else:
duration = 2 * 60 # 2 minutes

duration_in_ms = duration * 1000

await self.executor.async_execute_command(
OverkizCommand.RING_WITH_SINGLE_SIMPLE_SEQUENCE, # https://www.tahomalink.com/enduser-mobile-web/steer-html5-client/vendor/somfy/io/siren/const.js
# https://www.tahomalink.com/enduser-mobile-web/steer-html5-client/vendor/somfy/io/siren/const.js
OverkizCommand.RING_WITH_SINGLE_SIMPLE_SEQUENCE,
duration_in_ms, # duration
75, # 90 seconds bip, 30 seconds silence
2, # repeat 3 times
OverkizCommandParam.MEMORIZED_VOLUME,
)

async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Send the off command."""
await self.executor.async_cancel_command(
[OverkizCommand.RING_WITH_SINGLE_SIMPLE_SEQUENCE]
)

await self.executor.async_execute_command(
OverkizCommand.ADVANCED_REFRESH, OverkizCommandParam.NORMAL
)
await self.executor.async_execute_command(OverkizCommand.OFF)