mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Add binary sensors for fridge doors in SmartThings (#141252)
* Add binary sensors for fridge doors * Add binary sensors for fridge doors * Add binary sensors for fridge doors * Add binary sensors for fridge doors
This commit is contained in:
parent
590c588557
commit
12e001cf2b
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pysmartthings import Attribute, Capability, Category, SmartThings
|
from pysmartthings import Attribute, Capability, Category, SmartThings
|
||||||
@ -35,6 +36,8 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
|
|||||||
is_on_key: str
|
is_on_key: str
|
||||||
category_device_class: dict[Category | str, BinarySensorDeviceClass] | None = None
|
category_device_class: dict[Category | str, BinarySensorDeviceClass] | None = None
|
||||||
category: set[Category] | None = None
|
category: set[Category] | None = None
|
||||||
|
exists_fn: Callable[[str], bool] | None = None
|
||||||
|
component_translation_key: dict[str, str] | None = None
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_TO_SENSORS: dict[
|
CAPABILITY_TO_SENSORS: dict[
|
||||||
@ -58,6 +61,11 @@ CAPABILITY_TO_SENSORS: dict[
|
|||||||
Category.DOOR: BinarySensorDeviceClass.DOOR,
|
Category.DOOR: BinarySensorDeviceClass.DOOR,
|
||||||
Category.WINDOW: BinarySensorDeviceClass.WINDOW,
|
Category.WINDOW: BinarySensorDeviceClass.WINDOW,
|
||||||
},
|
},
|
||||||
|
exists_fn=lambda key: key in {"freezer", "cooler"},
|
||||||
|
component_translation_key={
|
||||||
|
"freezer": "freezer_door",
|
||||||
|
"cooler": "cooler_door",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
Capability.FILTER_STATUS: {
|
Capability.FILTER_STATUS: {
|
||||||
@ -164,17 +172,18 @@ async def async_setup_entry(
|
|||||||
entry_data = entry.runtime_data
|
entry_data = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
SmartThingsBinarySensor(
|
SmartThingsBinarySensor(
|
||||||
entry_data.client,
|
entry_data.client, device, description, capability, attribute, component
|
||||||
device,
|
|
||||||
description,
|
|
||||||
capability,
|
|
||||||
attribute,
|
|
||||||
)
|
)
|
||||||
for device in entry_data.devices.values()
|
for device in entry_data.devices.values()
|
||||||
for capability, attribute_map in CAPABILITY_TO_SENSORS.items()
|
for capability, attribute_map in CAPABILITY_TO_SENSORS.items()
|
||||||
if capability in device.status[MAIN]
|
|
||||||
for attribute, description in attribute_map.items()
|
for attribute, description in attribute_map.items()
|
||||||
if (
|
for component in device.status
|
||||||
|
if capability in device.status[component]
|
||||||
|
and (
|
||||||
|
component == MAIN
|
||||||
|
or (description.exists_fn is not None and description.exists_fn(component))
|
||||||
|
)
|
||||||
|
and (
|
||||||
not description.category
|
not description.category
|
||||||
or get_main_component_category(device) in description.category
|
or get_main_component_category(device) in description.category
|
||||||
)
|
)
|
||||||
@ -193,9 +202,10 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
|
|||||||
entity_description: SmartThingsBinarySensorEntityDescription,
|
entity_description: SmartThingsBinarySensorEntityDescription,
|
||||||
capability: Capability,
|
capability: Capability,
|
||||||
attribute: Attribute,
|
attribute: Attribute,
|
||||||
|
component: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init the class."""
|
"""Init the class."""
|
||||||
super().__init__(client, device, {capability})
|
super().__init__(client, device, {capability}, component=component)
|
||||||
self._attribute = attribute
|
self._attribute = attribute
|
||||||
self.capability = capability
|
self.capability = capability
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
@ -207,6 +217,19 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
|
|||||||
):
|
):
|
||||||
self._attr_device_class = entity_description.category_device_class[category]
|
self._attr_device_class = entity_description.category_device_class[category]
|
||||||
self._attr_name = None
|
self._attr_name = None
|
||||||
|
if (
|
||||||
|
entity_description.component_translation_key is not None
|
||||||
|
and (
|
||||||
|
translation_key := entity_description.component_translation_key.get(
|
||||||
|
component
|
||||||
|
)
|
||||||
|
)
|
||||||
|
is not None
|
||||||
|
):
|
||||||
|
self._attr_translation_key = translation_key
|
||||||
|
self._attr_unique_id = (
|
||||||
|
f"{device.device.device_id}_{component}_{capability}_{attribute}"
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
"filter_status": {
|
"filter_status": {
|
||||||
"name": "Filter status"
|
"name": "Filter status"
|
||||||
},
|
},
|
||||||
|
"freezer_door": {
|
||||||
|
"name": "Freezer door"
|
||||||
|
},
|
||||||
|
"cooler_door": {
|
||||||
|
"name": "Cooler door"
|
||||||
|
},
|
||||||
"remote_control": {
|
"remote_control": {
|
||||||
"name": "Remote control"
|
"name": "Remote control"
|
||||||
},
|
},
|
||||||
|
@ -569,6 +569,54 @@
|
|||||||
'state': 'on',
|
'state': 'on',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_cooler_door-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'binary_sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'binary_sensor.refrigerator_cooler_door',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Cooler door',
|
||||||
|
'platform': 'smartthings',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'cooler_door',
|
||||||
|
'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_cooler_contactSensor_contact',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_cooler_door-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Refrigerator Cooler door',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.refrigerator_cooler_door',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_door-entry]
|
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_door-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -617,6 +665,54 @@
|
|||||||
'state': 'off',
|
'state': 'off',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_freezer_door-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'binary_sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'binary_sensor.refrigerator_freezer_door',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Freezer door',
|
||||||
|
'platform': 'smartthings',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'freezer_door',
|
||||||
|
'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_freezer_contactSensor_contact',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[da_ref_normal_000001][binary_sensor.refrigerator_freezer_door-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'door',
|
||||||
|
'friendly_name': 'Refrigerator Freezer door',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.refrigerator_freezer_door',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_all_entities[da_wm_dw_000001][binary_sensor.dishwasher_child_lock-entry]
|
# name: test_all_entities[da_wm_dw_000001][binary_sensor.dishwasher_child_lock-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user