mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 02:28:21 +00:00
fix review comments and more
This commit is contained in:
parent
526b344456
commit
625ecdda6d
@ -156,29 +156,20 @@
|
|||||||
"external_binary_input": {
|
"external_binary_input": {
|
||||||
"name": "Child Lock"
|
"name": "Child Lock"
|
||||||
},
|
},
|
||||||
"identification_mode": {
|
|
||||||
"name": "Identification Mode"
|
|
||||||
},
|
|
||||||
"manual_operation": {
|
"manual_operation": {
|
||||||
"name": "Manual Operation"
|
"name": "Manual Operation"
|
||||||
},
|
},
|
||||||
"motor_rotation": {
|
"on_off_instance": {
|
||||||
"name": "Motor rotation direction"
|
"name": "Switch {instance}"
|
||||||
},
|
},
|
||||||
"restore_last_known_state": {
|
"watchdog": {
|
||||||
"name": "Restore last known state"
|
|
||||||
},
|
|
||||||
"switch_type": {
|
|
||||||
"name": "Switch Type"
|
|
||||||
},
|
|
||||||
"watchdog_on_off": {
|
|
||||||
"name": "Watchdog"
|
"name": "Watchdog"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"connection_closed": {
|
"connection_closed": {
|
||||||
"message": "Could not connect to Homee while setting attribute"
|
"message": "Could not connect to Homee while setting attribute."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,26 +50,14 @@ SWITCH_DESCRIPTIONS: dict[AttributeType, HomeeSwitchEntityDescription] = {
|
|||||||
AttributeType.EXTERNAL_BINARY_INPUT: HomeeSwitchEntityDescription(
|
AttributeType.EXTERNAL_BINARY_INPUT: HomeeSwitchEntityDescription(
|
||||||
key="external_binary_input", entity_category=EntityCategory.CONFIG
|
key="external_binary_input", entity_category=EntityCategory.CONFIG
|
||||||
),
|
),
|
||||||
AttributeType.IDENTIFICATION_MODE: HomeeSwitchEntityDescription(
|
|
||||||
key="identification_mode", entity_category=EntityCategory.DIAGNOSTIC
|
|
||||||
),
|
|
||||||
AttributeType.MANUAL_OPERATION: HomeeSwitchEntityDescription(
|
AttributeType.MANUAL_OPERATION: HomeeSwitchEntityDescription(
|
||||||
key="manual_operation"
|
key="manual_operation"
|
||||||
),
|
),
|
||||||
AttributeType.MOTOR_ROTATION: HomeeSwitchEntityDescription(
|
|
||||||
key="motor_rotation", entity_category=EntityCategory.CONFIG
|
|
||||||
),
|
|
||||||
AttributeType.ON_OFF: HomeeSwitchEntityDescription(
|
AttributeType.ON_OFF: HomeeSwitchEntityDescription(
|
||||||
key="on_off", device_class_fn=get_device_class, name=None
|
key="on_off", device_class_fn=get_device_class, name=None
|
||||||
),
|
),
|
||||||
AttributeType.RESTORE_LAST_KNOWN_STATE: HomeeSwitchEntityDescription(
|
|
||||||
key="restore_last_known_state", entity_category=EntityCategory.CONFIG
|
|
||||||
),
|
|
||||||
AttributeType.SWITCH_TYPE: HomeeSwitchEntityDescription(
|
|
||||||
key="switch_type", entity_category=EntityCategory.CONFIG
|
|
||||||
),
|
|
||||||
AttributeType.WATCHDOG_ON_OFF: HomeeSwitchEntityDescription(
|
AttributeType.WATCHDOG_ON_OFF: HomeeSwitchEntityDescription(
|
||||||
key="watchdog_on_off", entity_category=EntityCategory.CONFIG
|
key="watchdog", entity_category=EntityCategory.CONFIG
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +74,7 @@ async def async_setup_entry(
|
|||||||
devices.extend(
|
devices.extend(
|
||||||
HomeeSwitch(attribute, config_entry, SWITCH_DESCRIPTIONS[attribute.type])
|
HomeeSwitch(attribute, config_entry, SWITCH_DESCRIPTIONS[attribute.type])
|
||||||
for attribute in node.attributes
|
for attribute in node.attributes
|
||||||
if (
|
if (attribute.type in SWITCH_DESCRIPTIONS and attribute.editable)
|
||||||
attribute.type in SWITCH_DESCRIPTIONS
|
|
||||||
and attribute.editable
|
|
||||||
and attribute.maximum == 1
|
|
||||||
and attribute.step_value == 1
|
|
||||||
)
|
|
||||||
and not (
|
and not (
|
||||||
attribute.type == AttributeType.ON_OFF
|
attribute.type == AttributeType.ON_OFF
|
||||||
and node.profile in LIGHT_PROFILES
|
and node.profile in LIGHT_PROFILES
|
||||||
@ -123,9 +106,14 @@ class HomeeSwitch(HomeeEntity, SwitchEntity):
|
|||||||
if not ((attribute.type == AttributeType.ON_OFF) and (attribute.instance == 0)):
|
if not ((attribute.type == AttributeType.ON_OFF) and (attribute.instance == 0)):
|
||||||
self._attr_translation_key = description.key
|
self._attr_translation_key = description.key
|
||||||
if attribute.instance > 0:
|
if attribute.instance > 0:
|
||||||
self._attr_translation_key = f"{self._attr_translation_key}_instance"
|
self._attr_translation_key = f"{description.key}_instance"
|
||||||
self._attr_translation_placeholders = {"instance": str(attribute.instance)}
|
self._attr_translation_placeholders = {"instance": str(attribute.instance)}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Return True if entity is on."""
|
||||||
|
return bool(self._attribute.current_value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> SwitchDeviceClass:
|
def device_class(self) -> SwitchDeviceClass:
|
||||||
"""Return the device class of the switch."""
|
"""Return the device class of the switch."""
|
||||||
|
@ -67,6 +67,5 @@ def mock_homee() -> Generator[AsyncMock]:
|
|||||||
homee.connected = True
|
homee.connected = True
|
||||||
|
|
||||||
homee.get_access_token.return_value = "test_token"
|
homee.get_access_token.return_value = "test_token"
|
||||||
homee.get_node_by_id.return_value = None
|
|
||||||
|
|
||||||
yield homee
|
yield homee
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"security": 0,
|
"security": 0,
|
||||||
"attributes": [
|
"attributes": [
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 1,
|
||||||
"node_id": 1,
|
"node_id": 1,
|
||||||
"instance": 0,
|
"instance": 0,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
@ -40,49 +40,7 @@
|
|||||||
"name": ""
|
"name": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 4,
|
"id": 2,
|
||||||
"node_id": 1,
|
|
||||||
"instance": 0,
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 1,
|
|
||||||
"current_value": 1.0,
|
|
||||||
"target_value": 1.0,
|
|
||||||
"last_value": 1.0,
|
|
||||||
"unit": "n/a",
|
|
||||||
"step_value": 1.0,
|
|
||||||
"editable": 1,
|
|
||||||
"type": 170,
|
|
||||||
"state": 1,
|
|
||||||
"last_changed": 1672169339,
|
|
||||||
"changed_by": 1,
|
|
||||||
"changed_by_id": 0,
|
|
||||||
"based_on": 1,
|
|
||||||
"data": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"node_id": 1,
|
|
||||||
"instance": 1,
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 1,
|
|
||||||
"current_value": 0.0,
|
|
||||||
"target_value": 0.0,
|
|
||||||
"last_value": 0.0,
|
|
||||||
"unit": "n/a",
|
|
||||||
"step_value": 1.0,
|
|
||||||
"editable": 1,
|
|
||||||
"type": 304,
|
|
||||||
"state": 1,
|
|
||||||
"last_changed": 1738679948,
|
|
||||||
"changed_by": 1,
|
|
||||||
"changed_by_id": 0,
|
|
||||||
"based_on": 4,
|
|
||||||
"data": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 8,
|
|
||||||
"node_id": 1,
|
"node_id": 1,
|
||||||
"instance": 0,
|
"instance": 0,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
@ -103,30 +61,9 @@
|
|||||||
"name": ""
|
"name": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 9,
|
"id": 3,
|
||||||
"node_id": 1,
|
"node_id": 1,
|
||||||
"instance": 0,
|
"instance": 1,
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 1,
|
|
||||||
"current_value": 0.0,
|
|
||||||
"target_value": 0.0,
|
|
||||||
"last_value": 0.0,
|
|
||||||
"unit": "n/a",
|
|
||||||
"step_value": 1.0,
|
|
||||||
"editable": 1,
|
|
||||||
"type": 324,
|
|
||||||
"state": 1,
|
|
||||||
"last_changed": 1615396155,
|
|
||||||
"changed_by": 1,
|
|
||||||
"changed_by_id": 0,
|
|
||||||
"based_on": 1,
|
|
||||||
"data": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 11,
|
|
||||||
"node_id": 1,
|
|
||||||
"instance": 0,
|
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
"maximum": 1,
|
"maximum": 1,
|
||||||
"current_value": 0.0,
|
"current_value": 0.0,
|
||||||
@ -145,9 +82,9 @@
|
|||||||
"name": ""
|
"name": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 14,
|
"id": 4,
|
||||||
"node_id": 1,
|
"node_id": 1,
|
||||||
"instance": 0,
|
"instance": 2,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
"maximum": 1,
|
"maximum": 1,
|
||||||
"current_value": 1.0,
|
"current_value": 1.0,
|
||||||
@ -156,9 +93,9 @@
|
|||||||
"unit": "n/a",
|
"unit": "n/a",
|
||||||
"step_value": 1.0,
|
"step_value": 1.0,
|
||||||
"editable": 1,
|
"editable": 1,
|
||||||
"type": 133,
|
"type": 1,
|
||||||
"state": 1,
|
"state": 1,
|
||||||
"last_changed": 1711299215,
|
"last_changed": 1736743294,
|
||||||
"changed_by": 1,
|
"changed_by": 1,
|
||||||
"changed_by_id": 0,
|
"changed_by_id": 0,
|
||||||
"based_on": 1,
|
"based_on": 1,
|
||||||
@ -166,49 +103,7 @@
|
|||||||
"name": ""
|
"name": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 15,
|
"id": 5,
|
||||||
"node_id": 1,
|
|
||||||
"instance": 0,
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 2,
|
|
||||||
"current_value": 1.0,
|
|
||||||
"target_value": 1.0,
|
|
||||||
"last_value": 1.0,
|
|
||||||
"unit": "",
|
|
||||||
"step_value": 1.0,
|
|
||||||
"editable": 1,
|
|
||||||
"type": 63,
|
|
||||||
"state": 1,
|
|
||||||
"last_changed": 1694992768,
|
|
||||||
"changed_by": 1,
|
|
||||||
"changed_by_id": 0,
|
|
||||||
"based_on": 1,
|
|
||||||
"data": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 16,
|
|
||||||
"node_id": 1,
|
|
||||||
"instance": 1,
|
|
||||||
"minimum": 0,
|
|
||||||
"maximum": 2,
|
|
||||||
"current_value": 1.0,
|
|
||||||
"target_value": 1.0,
|
|
||||||
"last_value": 1.0,
|
|
||||||
"unit": "",
|
|
||||||
"step_value": 1.0,
|
|
||||||
"editable": 1,
|
|
||||||
"type": 63,
|
|
||||||
"state": 1,
|
|
||||||
"last_changed": 1694992768,
|
|
||||||
"changed_by": 1,
|
|
||||||
"changed_by_id": 0,
|
|
||||||
"based_on": 1,
|
|
||||||
"data": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 18,
|
|
||||||
"node_id": 1,
|
"node_id": 1,
|
||||||
"instance": 0,
|
"instance": 0,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
|
@ -1,51 +1,4 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_switch_snapshot[switch.test_switch-entry]
|
|
||||||
EntityRegistryEntrySnapshot({
|
|
||||||
'aliases': set({
|
|
||||||
}),
|
|
||||||
'area_id': None,
|
|
||||||
'capabilities': None,
|
|
||||||
'config_entry_id': <ANY>,
|
|
||||||
'device_class': None,
|
|
||||||
'device_id': <ANY>,
|
|
||||||
'disabled_by': None,
|
|
||||||
'domain': 'switch',
|
|
||||||
'entity_category': None,
|
|
||||||
'entity_id': 'switch.test_switch',
|
|
||||||
'has_entity_name': True,
|
|
||||||
'hidden_by': None,
|
|
||||||
'icon': None,
|
|
||||||
'id': <ANY>,
|
|
||||||
'labels': set({
|
|
||||||
}),
|
|
||||||
'name': None,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
|
||||||
'original_icon': None,
|
|
||||||
'original_name': None,
|
|
||||||
'platform': 'homee',
|
|
||||||
'previous_unique_id': None,
|
|
||||||
'supported_features': 0,
|
|
||||||
'translation_key': None,
|
|
||||||
'unique_id': '00055511EECC-1-11',
|
|
||||||
'unit_of_measurement': None,
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_switch_snapshot[switch.test_switch-state]
|
|
||||||
StateSnapshot({
|
|
||||||
'attributes': ReadOnlyDict({
|
|
||||||
'device_class': 'outlet',
|
|
||||||
'friendly_name': 'Test Switch',
|
|
||||||
}),
|
|
||||||
'context': <ANY>,
|
|
||||||
'entity_id': 'switch.test_switch',
|
|
||||||
'last_changed': <ANY>,
|
|
||||||
'last_reported': <ANY>,
|
|
||||||
'last_updated': <ANY>,
|
|
||||||
'state': 'off',
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_switch_snapshot[switch.test_switch_child_lock-entry]
|
# name: test_switch_snapshot[switch.test_switch_child_lock-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -75,7 +28,7 @@
|
|||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': 'external_binary_input',
|
'translation_key': 'external_binary_input',
|
||||||
'unique_id': '00055511EECC-1-3',
|
'unique_id': '00055511EECC-1-1',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
@ -93,53 +46,6 @@
|
|||||||
'state': 'off',
|
'state': 'off',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_switch_snapshot[switch.test_switch_identification_mode-entry]
|
|
||||||
EntityRegistryEntrySnapshot({
|
|
||||||
'aliases': set({
|
|
||||||
}),
|
|
||||||
'area_id': None,
|
|
||||||
'capabilities': None,
|
|
||||||
'config_entry_id': <ANY>,
|
|
||||||
'device_class': None,
|
|
||||||
'device_id': <ANY>,
|
|
||||||
'disabled_by': None,
|
|
||||||
'domain': 'switch',
|
|
||||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
|
||||||
'entity_id': 'switch.test_switch_identification_mode',
|
|
||||||
'has_entity_name': True,
|
|
||||||
'hidden_by': None,
|
|
||||||
'icon': None,
|
|
||||||
'id': <ANY>,
|
|
||||||
'labels': set({
|
|
||||||
}),
|
|
||||||
'name': None,
|
|
||||||
'options': dict({
|
|
||||||
}),
|
|
||||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
|
||||||
'original_icon': None,
|
|
||||||
'original_name': 'Identification Mode',
|
|
||||||
'platform': 'homee',
|
|
||||||
'previous_unique_id': None,
|
|
||||||
'supported_features': 0,
|
|
||||||
'translation_key': 'identification_mode',
|
|
||||||
'unique_id': '00055511EECC-1-4',
|
|
||||||
'unit_of_measurement': None,
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_switch_snapshot[switch.test_switch_identification_mode-state]
|
|
||||||
StateSnapshot({
|
|
||||||
'attributes': ReadOnlyDict({
|
|
||||||
'device_class': 'switch',
|
|
||||||
'friendly_name': 'Test Switch Identification Mode',
|
|
||||||
}),
|
|
||||||
'context': <ANY>,
|
|
||||||
'entity_id': 'switch.test_switch_identification_mode',
|
|
||||||
'last_changed': <ANY>,
|
|
||||||
'last_reported': <ANY>,
|
|
||||||
'last_updated': <ANY>,
|
|
||||||
'state': 'on',
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_switch_snapshot[switch.test_switch_manual_operation-entry]
|
# name: test_switch_snapshot[switch.test_switch_manual_operation-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -169,7 +75,7 @@
|
|||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': 'manual_operation',
|
'translation_key': 'manual_operation',
|
||||||
'unique_id': '00055511EECC-1-8',
|
'unique_id': '00055511EECC-1-2',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
@ -187,7 +93,7 @@
|
|||||||
'state': 'off',
|
'state': 'off',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_switch_snapshot[switch.test_switch_motor_rotation_direction-entry]
|
# name: test_switch_snapshot[switch.test_switch_switch_1-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -198,8 +104,8 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'switch',
|
'domain': 'switch',
|
||||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
'entity_category': None,
|
||||||
'entity_id': 'switch.test_switch_motor_rotation_direction',
|
'entity_id': 'switch.test_switch_switch_1',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
'icon': None,
|
'icon': None,
|
||||||
@ -209,32 +115,32 @@
|
|||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Motor rotation direction',
|
'original_name': 'Switch 1',
|
||||||
'platform': 'homee',
|
'platform': 'homee',
|
||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': 'motor_rotation',
|
'translation_key': 'on_off_instance',
|
||||||
'unique_id': '00055511EECC-1-9',
|
'unique_id': '00055511EECC-1-3',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_switch_snapshot[switch.test_switch_motor_rotation_direction-state]
|
# name: test_switch_snapshot[switch.test_switch_switch_1-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'switch',
|
'device_class': 'outlet',
|
||||||
'friendly_name': 'Test Switch Motor rotation direction',
|
'friendly_name': 'Test Switch Switch 1',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'switch.test_switch_motor_rotation_direction',
|
'entity_id': 'switch.test_switch_switch_1',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'off',
|
'state': 'off',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_switch_snapshot[switch.test_switch_restore_last_known_state-entry]
|
# name: test_switch_snapshot[switch.test_switch_switch_2-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -245,8 +151,8 @@
|
|||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
'domain': 'switch',
|
'domain': 'switch',
|
||||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
'entity_category': None,
|
||||||
'entity_id': 'switch.test_switch_restore_last_known_state',
|
'entity_id': 'switch.test_switch_switch_2',
|
||||||
'has_entity_name': True,
|
'has_entity_name': True,
|
||||||
'hidden_by': None,
|
'hidden_by': None,
|
||||||
'icon': None,
|
'icon': None,
|
||||||
@ -256,25 +162,25 @@
|
|||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
'original_device_class': <SwitchDeviceClass.OUTLET: 'outlet'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Restore last known state',
|
'original_name': 'Switch 2',
|
||||||
'platform': 'homee',
|
'platform': 'homee',
|
||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': 'restore_last_known_state',
|
'translation_key': 'on_off_instance',
|
||||||
'unique_id': '00055511EECC-1-14',
|
'unique_id': '00055511EECC-1-4',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_switch_snapshot[switch.test_switch_restore_last_known_state-state]
|
# name: test_switch_snapshot[switch.test_switch_switch_2-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'switch',
|
'device_class': 'outlet',
|
||||||
'friendly_name': 'Test Switch Restore last known state',
|
'friendly_name': 'Test Switch Switch 2',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'switch.test_switch_restore_last_known_state',
|
'entity_id': 'switch.test_switch_switch_2',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
@ -309,8 +215,8 @@
|
|||||||
'platform': 'homee',
|
'platform': 'homee',
|
||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': 'watchdog_on_off',
|
'translation_key': 'watchdog',
|
||||||
'unique_id': '00055511EECC-1-18',
|
'unique_id': '00055511EECC-1-5',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -20,7 +20,7 @@ from . import build_mock_node, setup_integration
|
|||||||
from tests.common import MockConfigEntry, snapshot_platform
|
from tests.common import MockConfigEntry, snapshot_platform
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_on(
|
async def test_switch_turn_on(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_homee: MagicMock,
|
mock_homee: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
@ -30,18 +30,18 @@ async def test_switch_on(
|
|||||||
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
assert hass.states.get("switch.test_switch").state is not STATE_ON
|
assert hass.states.get("switch.test_switch_switch_1").state is not STATE_ON
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: "switch.test_switch"},
|
{ATTR_ENTITY_ID: "switch.test_switch_switch_1"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_homee.set_value.assert_called_once_with(1, 11, 1)
|
mock_homee.set_value.assert_called_once_with(1, 3, 1)
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_off(
|
async def test_switch_turn_off(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_homee: MagicMock,
|
mock_homee: MagicMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
@ -51,14 +51,14 @@ async def test_switch_off(
|
|||||||
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
assert hass.states.get("switch.test_switch_identification_mode").state is STATE_ON
|
assert hass.states.get("switch.test_switch_watchdog").state is STATE_ON
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: "switch.test_switch_identification_mode"},
|
{ATTR_ENTITY_ID: "switch.test_switch_watchdog"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
mock_homee.set_value.assert_called_once_with(1, 4, 0)
|
mock_homee.set_value.assert_called_once_with(1, 5, 0)
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_device_class(
|
async def test_switch_device_class(
|
||||||
@ -72,7 +72,7 @@ async def test_switch_device_class(
|
|||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("switch.test_switch").attributes["device_class"]
|
hass.states.get("switch.test_switch_switch_1").attributes["device_class"]
|
||||||
== SwitchDeviceClass.OUTLET
|
== SwitchDeviceClass.OUTLET
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
@ -93,7 +93,7 @@ async def test_switch_device_class_no_outlet(
|
|||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("switch.test_switch").attributes["device_class"]
|
hass.states.get("switch.test_switch_switch_1").attributes["device_class"]
|
||||||
== SwitchDeviceClass.SWITCH
|
== SwitchDeviceClass.SWITCH
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,3 +112,21 @@ async def test_switch_snapshot(
|
|||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_switch_state(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_homee: MagicMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test if the correct state is returned."""
|
||||||
|
mock_homee.nodes = [build_mock_node("switches.json")]
|
||||||
|
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
|
assert hass.states.get("switch.test_switch_switch_1").state is not STATE_ON
|
||||||
|
switch = mock_homee.nodes[0].attributes[2]
|
||||||
|
switch.current_value = 1
|
||||||
|
switch.add_on_changed_listener.call_args_list[0][0][0](switch)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get("switch.test_switch_switch_1").state is STATE_ON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user