mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Migrate kmtronic to has entity name (#107469)
This commit is contained in:
parent
af209fe2b8
commit
1171a7a3d9
@ -29,5 +29,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"switch": {
|
||||||
|
"relay": {
|
||||||
|
"name": "Relay {relay_id}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,9 @@ async def async_setup_entry(
|
|||||||
class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
|
class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
|
||||||
"""KMtronic Switch Entity."""
|
"""KMtronic Switch Entity."""
|
||||||
|
|
||||||
|
_attr_translation_key = "relay"
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, hub, coordinator, relay, reverse, config_entry_id):
|
def __init__(self, hub, coordinator, relay, reverse, config_entry_id):
|
||||||
"""Pass coordinator to CoordinatorEntity."""
|
"""Pass coordinator to CoordinatorEntity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
@ -46,7 +49,7 @@ class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
|
|||||||
configuration_url=hub.host,
|
configuration_url=hub.host,
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_name = f"Relay{relay.id}"
|
self._attr_translation_placeholders = {"relay_id": relay.id}
|
||||||
self._attr_unique_id = f"{config_entry_id}_relay{relay.id}"
|
self._attr_unique_id = f"{config_entry_id}_relay{relay.id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -39,15 +39,18 @@ async def test_relay_on_off(
|
|||||||
text="",
|
text="",
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch", "turn_on", {"entity_id": "switch.relay1"}, blocking=True
|
"switch",
|
||||||
|
"turn_on",
|
||||||
|
{"entity_id": "switch.controller_1_1_1_1_relay_1"},
|
||||||
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
# Mocks the response for turning a relay1 off
|
# Mocks the response for turning a relay1 off
|
||||||
@ -57,11 +60,14 @@ async def test_relay_on_off(
|
|||||||
)
|
)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch", "turn_off", {"entity_id": "switch.relay1"}, blocking=True
|
"switch",
|
||||||
|
"turn_off",
|
||||||
|
{"entity_id": "switch.controller_1_1_1_1_relay_1"},
|
||||||
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
# Mocks the response for turning a relay1 on
|
# Mocks the response for turning a relay1 on
|
||||||
@ -71,11 +77,14 @@ async def test_relay_on_off(
|
|||||||
)
|
)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch", "toggle", {"entity_id": "switch.relay1"}, blocking=True
|
"switch",
|
||||||
|
"toggle",
|
||||||
|
{"entity_id": "switch.controller_1_1_1_1_relay_1"},
|
||||||
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +104,7 @@ async def test_update(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
|
|||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
aioclient_mock.clear_requests()
|
aioclient_mock.clear_requests()
|
||||||
@ -106,7 +115,7 @@ async def test_update(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
|
|||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +137,7 @@ async def test_failed_update(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {})
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
aioclient_mock.clear_requests()
|
aioclient_mock.clear_requests()
|
||||||
@ -140,7 +149,7 @@ async def test_failed_update(
|
|||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
future += timedelta(minutes=10)
|
future += timedelta(minutes=10)
|
||||||
@ -152,7 +161,7 @@ async def test_failed_update(
|
|||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
@ -180,15 +189,18 @@ async def test_relay_on_off_reversed(
|
|||||||
text="",
|
text="",
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch", "turn_off", {"entity_id": "switch.relay1"}, blocking=True
|
"switch",
|
||||||
|
"turn_off",
|
||||||
|
{"entity_id": "switch.controller_1_1_1_1_relay_1"},
|
||||||
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
# Mocks the response for turning a relay1 off
|
# Mocks the response for turning a relay1 off
|
||||||
@ -198,9 +210,12 @@ async def test_relay_on_off_reversed(
|
|||||||
)
|
)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"switch", "turn_on", {"entity_id": "switch.relay1"}, blocking=True
|
"switch",
|
||||||
|
"turn_on",
|
||||||
|
{"entity_id": "switch.controller_1_1_1_1_relay_1"},
|
||||||
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("switch.relay1")
|
state = hass.states.get("switch.controller_1_1_1_1_relay_1")
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user