mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 03:07:50 +00:00
Make sure SmartThings light can deal with unknown states (#140190)
* Fix * add comment * Make light unknown * Make light unknown
This commit is contained in:
parent
38e6133202
commit
b5c7bdd98f
@ -147,9 +147,16 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
|||||||
"""Update entity attributes when the device status has changed."""
|
"""Update entity attributes when the device status has changed."""
|
||||||
# Brightness and transition
|
# Brightness and transition
|
||||||
if brightness_supported(self._attr_supported_color_modes):
|
if brightness_supported(self._attr_supported_color_modes):
|
||||||
|
if (
|
||||||
|
brightness := self.get_attribute_value(
|
||||||
|
Capability.SWITCH_LEVEL, Attribute.LEVEL
|
||||||
|
)
|
||||||
|
) is None:
|
||||||
|
self._attr_brightness = None
|
||||||
|
else:
|
||||||
self._attr_brightness = int(
|
self._attr_brightness = int(
|
||||||
convert_scale(
|
convert_scale(
|
||||||
self.get_attribute_value(Capability.SWITCH_LEVEL, Attribute.LEVEL),
|
brightness,
|
||||||
100,
|
100,
|
||||||
255,
|
255,
|
||||||
0,
|
0,
|
||||||
@ -162,9 +169,14 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
|||||||
)
|
)
|
||||||
# Color
|
# Color
|
||||||
if ColorMode.HS in self._attr_supported_color_modes:
|
if ColorMode.HS in self._attr_supported_color_modes:
|
||||||
|
if (
|
||||||
|
hue := self.get_attribute_value(Capability.COLOR_CONTROL, Attribute.HUE)
|
||||||
|
) is None:
|
||||||
|
self._attr_hs_color = None
|
||||||
|
else:
|
||||||
self._attr_hs_color = (
|
self._attr_hs_color = (
|
||||||
convert_scale(
|
convert_scale(
|
||||||
self.get_attribute_value(Capability.COLOR_CONTROL, Attribute.HUE),
|
hue,
|
||||||
100,
|
100,
|
||||||
360,
|
360,
|
||||||
),
|
),
|
||||||
@ -217,6 +229,10 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
|||||||
super()._update_handler(event)
|
super()._update_handler(event)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool | None:
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
return self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH) == "on"
|
if (
|
||||||
|
state := self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH)
|
||||||
|
) is None:
|
||||||
|
return None
|
||||||
|
return state == "on"
|
||||||
|
@ -123,6 +123,7 @@ def mock_smartthings() -> Generator[AsyncMock]:
|
|||||||
"generic_ef00_v1",
|
"generic_ef00_v1",
|
||||||
"bosch_radiator_thermostat_ii",
|
"bosch_radiator_thermostat_ii",
|
||||||
"im_speaker_ai_0001",
|
"im_speaker_ai_0001",
|
||||||
|
"abl_light_b_001",
|
||||||
"tplink_p110",
|
"tplink_p110",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"components": {
|
||||||
|
"main": {
|
||||||
|
"switchLevel": {
|
||||||
|
"levelRange": {
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"level": {
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"switch": {
|
||||||
|
"switch": {
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"colorTemperature": {
|
||||||
|
"colorTemperatureRange": {
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"colorTemperature": {
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"deviceId": "7c16163e-c94e-482f-95f6-139ae0cd9d5e",
|
||||||
|
"name": "ABL Wafer Down Light(BLE)",
|
||||||
|
"label": "Kitchen Light 5",
|
||||||
|
"manufacturerName": "Samsung Electronics",
|
||||||
|
"presentationId": "ABL-LIGHT-B-001",
|
||||||
|
"deviceManufacturerCode": "Samsung Electronics",
|
||||||
|
"locationId": "6c314222-8baf-48a0-9442-5b1102a8757f",
|
||||||
|
"ownerId": "f24ff388-700c-7d1e-91f2-1c37ae68ce2b",
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"id": "main",
|
||||||
|
"label": "main",
|
||||||
|
"capabilities": [
|
||||||
|
{
|
||||||
|
"id": "switch",
|
||||||
|
"version": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "colorTemperature",
|
||||||
|
"version": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "switchLevel",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"categories": [
|
||||||
|
{
|
||||||
|
"name": "Light",
|
||||||
|
"categoryType": "manufacturer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"createTime": "2025-03-08T22:40:25.073Z",
|
||||||
|
"profile": {
|
||||||
|
"id": "65f5db53-9a78-4b19-8e40-d32187cd59ab"
|
||||||
|
},
|
||||||
|
"bleD2D": {
|
||||||
|
"encryptionKey": "f593369dcea915f6352a4a42cd4b2ea6",
|
||||||
|
"cipher": "AES_128-CBC-PKCS7Padding",
|
||||||
|
"advertisingId": "b13d7192",
|
||||||
|
"identifier": "88-57-1d-7c-cb-cf",
|
||||||
|
"configurationUrl": "https://apis.samsungiotcloud.com/v1/miniature/profile/65f5db53-9a78-4b19-8e40-d32187cd59ab",
|
||||||
|
"bleDeviceType": "BLE",
|
||||||
|
"metadata": null
|
||||||
|
},
|
||||||
|
"type": "BLE_D2D",
|
||||||
|
"restrictionTier": 0,
|
||||||
|
"allowed": null,
|
||||||
|
"executionContext": "CLOUD",
|
||||||
|
"relationships": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"_links": {}
|
||||||
|
}
|
@ -2,6 +2,39 @@
|
|||||||
# name: test_button_event[button]
|
# name: test_button_event[button]
|
||||||
<Event smartthings.button[L]: component_id=main, device_id=c4bdd19f-85d1-4d58-8f9c-e75ac3cf113b, location_id=abc, value=pushed, name=button, data=None>
|
<Event smartthings.button[L]: component_id=main, device_id=c4bdd19f-85d1-4d58-8f9c-e75ac3cf113b, location_id=abc, value=pushed, name=button, data=None>
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_devices[abl_light_b_001]
|
||||||
|
DeviceRegistryEntrySnapshot({
|
||||||
|
'area_id': None,
|
||||||
|
'config_entries': <ANY>,
|
||||||
|
'config_entries_subentries': <ANY>,
|
||||||
|
'configuration_url': 'https://account.smartthings.com',
|
||||||
|
'connections': set({
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'entry_type': None,
|
||||||
|
'hw_version': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'identifiers': set({
|
||||||
|
tuple(
|
||||||
|
'smartthings',
|
||||||
|
'7c16163e-c94e-482f-95f6-139ae0cd9d5e',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'is_new': False,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'manufacturer': None,
|
||||||
|
'model': None,
|
||||||
|
'model_id': None,
|
||||||
|
'name': 'Kitchen Light 5',
|
||||||
|
'name_by_user': None,
|
||||||
|
'primary_config_entry': <ANY>,
|
||||||
|
'serial_number': None,
|
||||||
|
'suggested_area': None,
|
||||||
|
'sw_version': None,
|
||||||
|
'via_device_id': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_devices[aeotec_home_energy_meter_gen5]
|
# name: test_devices[aeotec_home_energy_meter_gen5]
|
||||||
DeviceRegistryEntrySnapshot({
|
DeviceRegistryEntrySnapshot({
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
|
@ -1,4 +1,74 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_all_entities[abl_light_b_001][light.kitchen_light_5-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
'max_color_temp_kelvin': 9000,
|
||||||
|
'max_mireds': 500,
|
||||||
|
'min_color_temp_kelvin': 2000,
|
||||||
|
'min_mireds': 111,
|
||||||
|
'supported_color_modes': list([
|
||||||
|
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'light',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'light.kitchen_light_5',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'smartthings',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <LightEntityFeature: 32>,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '7c16163e-c94e-482f-95f6-139ae0cd9d5e',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[abl_light_b_001][light.kitchen_light_5-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'brightness': None,
|
||||||
|
'color_mode': None,
|
||||||
|
'color_temp': None,
|
||||||
|
'color_temp_kelvin': None,
|
||||||
|
'friendly_name': 'Kitchen Light 5',
|
||||||
|
'hs_color': None,
|
||||||
|
'max_color_temp_kelvin': 9000,
|
||||||
|
'max_mireds': 500,
|
||||||
|
'min_color_temp_kelvin': 2000,
|
||||||
|
'min_mireds': 111,
|
||||||
|
'rgb_color': None,
|
||||||
|
'supported_color_modes': list([
|
||||||
|
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||||
|
]),
|
||||||
|
'supported_features': <LightEntityFeature: 32>,
|
||||||
|
'xy_color': None,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'light.kitchen_light_5',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_all_entities[centralite][light.dimmer_debian-entry]
|
# name: test_all_entities[centralite][light.dimmer_debian-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user