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 priority lock #545

Merged
merged 3 commits into from
Aug 24, 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
12 changes: 7 additions & 5 deletions custom_components/tahoma/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ async def async_setup_entry(
}

for device in coordinator.data.values():
for state in device.states:
description = key_supported_states.get(state.name)

if description:
for state in device.definition.states:
if description := key_supported_states.get(state.qualified_name):
entities.append(
OverkizBinarySensor(
device.deviceurl,
Expand All @@ -112,5 +110,9 @@ class OverkizBinarySensor(OverkizDescriptiveEntity, BinarySensorEntity):
@property
def is_on(self):
"""Return the state of the sensor."""
state = self.device.states[self.entity_description.key]
state = self.device.states.get(self.entity_description.key)

if not state:
return None

return self.entity_description.is_on(state.value)
18 changes: 0 additions & 18 deletions custom_components/tahoma/cover_devices/tahoma_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,13 @@
CORE_OPEN_CLOSED_UNKNOWN_STATE = "core:OpenClosedUnknownState"
# io:DiscreteGateOpenerIOComponent
CORE_PEDESTRIAN_POSITION_STATE = "core:PedestrianPositionState"
CORE_PRIORITY_LOCK_TIMER_STATE = "core:PriorityLockTimerState"
CORE_SLATS_OPEN_CLOSED_STATE = "core:SlatsOpenClosedState"
CORE_SLATE_ORIENTATION_STATE = "core:SlateOrientationState"
CORE_SLATS_ORIENTATION_STATE = "core:SlatsOrientationState"
CORE_TARGET_CLOSURE_STATE = "core:TargetClosureState"
MYFOX_SHUTTER_STATUS_STATE = "myfox:ShutterStatusState"

IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState"
IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState"

ICON_LOCK_ALERT = "mdi:lock-alert"
ICON_WEATHER_WINDY = "mdi:weather-windy"

STATE_CLOSED = "closed"

Expand Down Expand Up @@ -128,19 +123,6 @@ def is_closed(self):

return None

@property
def icon(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally we got rid of this part <3

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

"""Return the icon to use in the frontend, if any."""
if (
self.executor.has_state(CORE_PRIORITY_LOCK_TIMER_STATE)
and self.executor.select_state(CORE_PRIORITY_LOCK_TIMER_STATE) > 0
):
if self.executor.select_state(IO_PRIORITY_LOCK_ORIGINATOR_STATE) == "wind":
return ICON_WEATHER_WINDY
return ICON_LOCK_ALERT

return None

async def async_open_cover_tilt(self, **_):
"""Open the cover tilt."""
await self.executor.async_execute_command(
Expand Down
30 changes: 21 additions & 9 deletions custom_components/tahoma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS,
TEMP_CELSIUS,
TIME_SECONDS,
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
VOLUME_LITERS,
)
Expand Down Expand Up @@ -98,11 +99,6 @@
device_class=sensor.DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="io:PriorityLockOriginatorState",
name="Priority Lock Originator",
icon="mdi:alert",
),
OverkizSensorDescription(
key="core:FossilEnergyConsumptionState",
name="Fossil Energy Consumption",
Expand Down Expand Up @@ -289,6 +285,20 @@
value=lambda value: str(value).capitalize(),
entity_registry_enabled_default=False,
),
OverkizSensorDescription(
key="io:PriorityLockOriginatorState",
name="Priority Lock Originator",
value=lambda value: str(value).capitalize(),
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitate with Unlocked as default value for this one, instead of Unknown.

icon="mdi:lock",
entity_registry_enabled_default=False,
),
OverkizSensorDescription(
key="core:PriorityLockTimerState",
name="Priority Lock Timer",
icon="mdi:lock-clock",
unit_of_measurement=TIME_SECONDS,
entity_registry_enabled_default=False,
),
]


Expand All @@ -308,9 +318,8 @@ async def async_setup_entry(
}

for device in coordinator.data.values():
for state in device.states:
description = key_supported_states.get(state.name)
if description:
for state in device.definition.states:
if description := key_supported_states.get(state.qualified_name):
entities.append(
OverkizStateSensor(
device.deviceurl,
Expand All @@ -328,7 +337,10 @@ class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
@property
def state(self):
"""Return the value of the sensor."""
state = self.device.states[self.entity_description.key]
state = self.device.states.get(self.entity_description.key)

if not state:
return None

# Transform the value with a lambda function
if hasattr(self.entity_description, "value"):
Expand Down