Add power cool and power freeze to SmartThings (#145102)

This commit is contained in:
Joost Lekkerkerker 2025-05-21 20:14:13 +02:00 committed by GitHub
parent c8ceea4be8
commit ea9fc6052d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 353 additions and 5 deletions

View File

@ -112,6 +112,12 @@
"ice_maker": { "ice_maker": {
"default": "mdi:delete-variant" "default": "mdi:delete-variant"
}, },
"power_cool": {
"default": "mdi:snowflake-alert"
},
"power_freeze": {
"default": "mdi:snowflake"
},
"sanitize": { "sanitize": {
"default": "mdi:lotion" "default": "mdi:lotion"
}, },

View File

@ -578,6 +578,12 @@
"sabbath_mode": { "sabbath_mode": {
"name": "Sabbath mode" "name": "Sabbath mode"
}, },
"power_cool": {
"name": "Power cool"
},
"power_freeze": {
"name": "Power freeze"
},
"auto_cycle_link": { "auto_cycle_link": {
"name": "Auto cycle link" "name": "Auto cycle link"
}, },

View File

@ -48,6 +48,9 @@ class SmartThingsSwitchEntityDescription(SwitchEntityDescription):
status_attribute: Attribute status_attribute: Attribute
component_translation_key: dict[str, str] | None = None component_translation_key: dict[str, str] | None = None
on_key: str = "on"
on_command: Command = Command.ON
off_command: Command = Command.OFF
@dataclass(frozen=True, kw_only=True) @dataclass(frozen=True, kw_only=True)
@ -98,6 +101,25 @@ CAPABILITY_TO_SWITCHES: dict[Capability | str, SmartThingsSwitchEntityDescriptio
key=Capability.SAMSUNG_CE_SABBATH_MODE, key=Capability.SAMSUNG_CE_SABBATH_MODE,
translation_key="sabbath_mode", translation_key="sabbath_mode",
status_attribute=Attribute.STATUS, status_attribute=Attribute.STATUS,
entity_category=EntityCategory.CONFIG,
),
Capability.SAMSUNG_CE_POWER_COOL: SmartThingsSwitchEntityDescription(
key=Capability.SAMSUNG_CE_POWER_COOL,
translation_key="power_cool",
status_attribute=Attribute.ACTIVATED,
on_key="True",
on_command=Command.ACTIVATE,
off_command=Command.DEACTIVATE,
entity_category=EntityCategory.CONFIG,
),
Capability.SAMSUNG_CE_POWER_FREEZE: SmartThingsSwitchEntityDescription(
key=Capability.SAMSUNG_CE_POWER_FREEZE,
translation_key="power_freeze",
status_attribute=Attribute.ACTIVATED,
on_key="True",
on_command=Command.ACTIVATE,
off_command=Command.DEACTIVATE,
entity_category=EntityCategory.CONFIG,
), ),
Capability.SAMSUNG_CE_STEAM_CLOSET_SANITIZE_MODE: SmartThingsSwitchEntityDescription( Capability.SAMSUNG_CE_STEAM_CLOSET_SANITIZE_MODE: SmartThingsSwitchEntityDescription(
key=Capability.SAMSUNG_CE_STEAM_CLOSET_SANITIZE_MODE, key=Capability.SAMSUNG_CE_STEAM_CLOSET_SANITIZE_MODE,
@ -239,14 +261,14 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity):
"""Turn the switch off.""" """Turn the switch off."""
await self.execute_device_command( await self.execute_device_command(
self.switch_capability, self.switch_capability,
Command.OFF, self.entity_description.off_command,
) )
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
await self.execute_device_command( await self.execute_device_command(
self.switch_capability, self.switch_capability,
Command.ON, self.entity_description.on_command,
) )
@property @property
@ -256,7 +278,7 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity):
self.get_attribute_value( self.get_attribute_value(
self.switch_capability, self.entity_description.status_attribute self.switch_capability, self.entity_description.status_attribute
) )
== "on" == self.entity_description.on_key
) )

View File

@ -574,7 +574,7 @@
}, },
"samsungce.powerCool": { "samsungce.powerCool": {
"activated": { "activated": {
"value": false, "value": true,
"timestamp": "2025-01-19T21:07:55.725Z" "timestamp": "2025-01-19T21:07:55.725Z"
} }
}, },

View File

@ -93,6 +93,100 @@
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_all_entities[da_ref_normal_000001][switch.refrigerator_power_cool-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.refrigerator_power_cool',
'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': 'Power cool',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_cool',
'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_main_samsungce.powerCool_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_000001][switch.refrigerator_power_cool-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Refrigerator Power cool',
}),
'context': <ANY>,
'entity_id': 'switch.refrigerator_power_cool',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_all_entities[da_ref_normal_000001][switch.refrigerator_power_freeze-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.refrigerator_power_freeze',
'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': 'Power freeze',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_freeze',
'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_main_samsungce.powerFreeze_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_000001][switch.refrigerator_power_freeze-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Refrigerator Power freeze',
}),
'context': <ANY>,
'entity_id': 'switch.refrigerator_power_freeze',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[da_ref_normal_000001][switch.refrigerator_sabbath_mode-entry] # name: test_all_entities[da_ref_normal_000001][switch.refrigerator_sabbath_mode-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
@ -105,7 +199,7 @@
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': None, 'disabled_by': None,
'domain': 'switch', 'domain': 'switch',
'entity_category': None, 'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.refrigerator_sabbath_mode', 'entity_id': 'switch.refrigerator_sabbath_mode',
'has_entity_name': True, 'has_entity_name': True,
'hidden_by': None, 'hidden_by': None,
@ -187,6 +281,194 @@
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_all_entities[da_ref_normal_01001][switch.refrigerator_power_cool-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.refrigerator_power_cool',
'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': 'Power cool',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_cool',
'unique_id': '7d3feb98-8a36-4351-c362-5e21ad3a78dd_main_samsungce.powerCool_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_01001][switch.refrigerator_power_cool-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Refrigerator Power cool',
}),
'context': <ANY>,
'entity_id': 'switch.refrigerator_power_cool',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[da_ref_normal_01001][switch.refrigerator_power_freeze-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.refrigerator_power_freeze',
'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': 'Power freeze',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_freeze',
'unique_id': '7d3feb98-8a36-4351-c362-5e21ad3a78dd_main_samsungce.powerFreeze_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_01001][switch.refrigerator_power_freeze-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Refrigerator Power freeze',
}),
'context': <ANY>,
'entity_id': 'switch.refrigerator_power_freeze',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[da_ref_normal_01011][switch.frigo_power_cool-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.frigo_power_cool',
'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': 'Power cool',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_cool',
'unique_id': '5758b2ec-563e-f39b-ec39-208e54aabf60_main_samsungce.powerCool_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_01011][switch.frigo_power_cool-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Frigo Power cool',
}),
'context': <ANY>,
'entity_id': 'switch.frigo_power_cool',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[da_ref_normal_01011][switch.frigo_power_freeze-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': 'switch',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.frigo_power_freeze',
'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': 'Power freeze',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_freeze',
'unique_id': '5758b2ec-563e-f39b-ec39-208e54aabf60_main_samsungce.powerFreeze_activated_activated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[da_ref_normal_01011][switch.frigo_power_freeze-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Frigo Power freeze',
}),
'context': <ANY>,
'entity_id': 'switch.frigo_power_freeze',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[da_rvc_normal_000001][switch.robot_vacuum-entry] # name: test_all_entities[da_rvc_normal_000001][switch.robot_vacuum-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@ -110,6 +110,38 @@ async def test_command_switch_turn_on_off(
) )
@pytest.mark.parametrize("device_fixture", ["da_ref_normal_000001"])
@pytest.mark.parametrize(
("action", "command"),
[
(SERVICE_TURN_ON, Command.ACTIVATE),
(SERVICE_TURN_OFF, Command.DEACTIVATE),
],
)
async def test_custom_commands(
hass: HomeAssistant,
devices: AsyncMock,
mock_config_entry: MockConfigEntry,
action: str,
command: Command,
) -> None:
"""Test switch turn on and off command."""
await setup_integration(hass, mock_config_entry)
await hass.services.async_call(
SWITCH_DOMAIN,
action,
{ATTR_ENTITY_ID: "switch.refrigerator_power_cool"},
blocking=True,
)
devices.execute_device_command.assert_called_once_with(
"7db87911-7dce-1cf2-7119-b953432a2f09",
Capability.SAMSUNG_CE_POWER_COOL,
command,
MAIN,
)
@pytest.mark.parametrize("device_fixture", ["c2c_arlo_pro_3_switch"]) @pytest.mark.parametrize("device_fixture", ["c2c_arlo_pro_3_switch"])
async def test_state_update( async def test_state_update(
hass: HomeAssistant, hass: HomeAssistant,