mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Fix TP-Link smart strip devices (#53799)
This commit is contained in:
parent
1c38e9168c
commit
b2725918b1
@ -180,9 +180,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
hass_data[COORDINATORS][
|
hass_data[COORDINATORS][
|
||||||
switch.mac
|
switch.context or switch.mac
|
||||||
] = coordinator = SmartPlugDataUpdateCoordinator(hass, switch)
|
] = coordinator = SmartPlugDataUpdateCoordinator(hass, switch)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
if unavailable_devices:
|
if unavailable_devices:
|
||||||
@ -275,4 +274,5 @@ class SmartPlugDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
except SmartDeviceException as ex:
|
except SmartDeviceException as ex:
|
||||||
raise UpdateFailed(ex) from ex
|
raise UpdateFailed(ex) from ex
|
||||||
|
|
||||||
|
self.name = data[CONF_ALIAS]
|
||||||
return data
|
return data
|
||||||
|
@ -101,7 +101,9 @@ async def async_setup_entry(
|
|||||||
]
|
]
|
||||||
switches: list[SmartPlug] = hass.data[TPLINK_DOMAIN][CONF_SWITCH]
|
switches: list[SmartPlug] = hass.data[TPLINK_DOMAIN][CONF_SWITCH]
|
||||||
for switch in switches:
|
for switch in switches:
|
||||||
coordinator: SmartPlugDataUpdateCoordinator = coordinators[switch.mac]
|
coordinator: SmartPlugDataUpdateCoordinator = coordinators[
|
||||||
|
switch.context or switch.mac
|
||||||
|
]
|
||||||
if not switch.has_emeter and coordinator.data.get(CONF_EMETER_PARAMS) is None:
|
if not switch.has_emeter and coordinator.data.get(CONF_EMETER_PARAMS) is None:
|
||||||
continue
|
continue
|
||||||
for description in ENERGY_SENSORS:
|
for description in ENERGY_SENSORS:
|
||||||
|
@ -39,7 +39,7 @@ async def async_setup_entry(
|
|||||||
]
|
]
|
||||||
switches: list[SmartPlug] = hass.data[TPLINK_DOMAIN][CONF_SWITCH]
|
switches: list[SmartPlug] = hass.data[TPLINK_DOMAIN][CONF_SWITCH]
|
||||||
for switch in switches:
|
for switch in switches:
|
||||||
coordinator = coordinators[switch.mac]
|
coordinator = coordinators[switch.context or switch.mac]
|
||||||
entities.append(SmartPlugSwitch(switch, coordinator))
|
entities.append(SmartPlugSwitch(switch, coordinator))
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
@ -61,31 +61,48 @@ SMARTPLUG_HS100_DATA = {
|
|||||||
"err_code": 0,
|
"err_code": 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SMARTSTRIPWITCH_DATA = {
|
SMARTSTRIP_KP303_DATA = {
|
||||||
"sysinfo": {
|
"sysinfo": {
|
||||||
"sw_ver": "1.0.4 Build 191111 Rel.143500",
|
"sw_ver": "1.0.4 Build 210428 Rel.135415",
|
||||||
"hw_ver": "4.0",
|
"hw_ver": "1.0",
|
||||||
"model": "HS110(EU)",
|
"model": "KP303(AU)",
|
||||||
"deviceId": "4C56447B395BB7A2FAC68C9DFEE2E84163222581",
|
"deviceId": "03102547AB1A57A4E4AA5B4EFE34C3005726B97D",
|
||||||
"oemId": "40F54B43071E9436B6395611E9D91CEA",
|
"oemId": "1F950FC9BFF278D9D35E046C129D9411",
|
||||||
"hwId": "A6C77E4FDD238B53D824AC8DA361F043",
|
"hwId": "9E86D4F840D2787D3D7A6523A731BA2C",
|
||||||
"rssi": -24,
|
"rssi": -74,
|
||||||
"longitude_i": 130793,
|
"longitude_i": 1158985,
|
||||||
"latitude_i": 480582,
|
"latitude_i": -319172,
|
||||||
"alias": "SmartPlug",
|
"alias": "TP-LINK_Power Strip_00B1",
|
||||||
"status": "new",
|
"status": "new",
|
||||||
"mic_type": "IOT.SMARTPLUGSWITCH",
|
"mic_type": "IOT.SMARTPLUGSWITCH",
|
||||||
"feature": "TIM",
|
"feature": "TIM",
|
||||||
"mac": "69:F2:3C:8E:E3:47",
|
"mac": "D4:DD:D6:95:B0:F9",
|
||||||
"updating": 0,
|
"updating": 0,
|
||||||
"led_off": 0,
|
"led_off": 0,
|
||||||
"relay_state": 0,
|
"children": [
|
||||||
"on_time": 0,
|
{
|
||||||
"active_mode": "none",
|
"id": "8006B399B7FE68D4E6991CCCEA239C081DFA913000",
|
||||||
"icon_hash": "",
|
"state": 0,
|
||||||
"dev_name": "Smart Wi-Fi Plug With Energy Monitoring",
|
"alias": "R-Plug 1",
|
||||||
"next_action": {"type": -1},
|
"on_time": 0,
|
||||||
"children": [{"id": "1", "state": 1, "alias": "SmartPlug#1"}],
|
"next_action": {"type": -1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "8006B399B7FE68D4E6991CCCEA239C081DFA913001",
|
||||||
|
"state": 1,
|
||||||
|
"alias": "R-Plug 2",
|
||||||
|
"on_time": 93835,
|
||||||
|
"next_action": {"type": -1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "8006B399B7FE68D4E6991CCCEA239C081DFA913002",
|
||||||
|
"state": 1,
|
||||||
|
"alias": "R-Plug 3",
|
||||||
|
"on_time": 93834,
|
||||||
|
"next_action": {"type": -1},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"child_num": 3,
|
||||||
"err_code": 0,
|
"err_code": 0,
|
||||||
},
|
},
|
||||||
"realtime": {
|
"realtime": {
|
||||||
|
@ -20,11 +20,10 @@ from homeassistant.components.tplink.const import (
|
|||||||
CONF_LIGHT,
|
CONF_LIGHT,
|
||||||
CONF_SW_VERSION,
|
CONF_SW_VERSION,
|
||||||
CONF_SWITCH,
|
CONF_SWITCH,
|
||||||
COORDINATORS,
|
|
||||||
UNAVAILABLE_RETRY_DELAY,
|
UNAVAILABLE_RETRY_DELAY,
|
||||||
)
|
)
|
||||||
from homeassistant.components.tplink.sensor import ENERGY_SENSORS
|
from homeassistant.components.tplink.sensor import ENERGY_SENSORS
|
||||||
from homeassistant.const import CONF_ALIAS, CONF_DEVICE_ID, CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -34,7 +33,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed, mock_coro
|
|||||||
from tests.components.tplink.consts import (
|
from tests.components.tplink.consts import (
|
||||||
SMARTPLUG_HS100_DATA,
|
SMARTPLUG_HS100_DATA,
|
||||||
SMARTPLUG_HS110_DATA,
|
SMARTPLUG_HS110_DATA,
|
||||||
SMARTSTRIPWITCH_DATA,
|
SMARTSTRIP_KP303_DATA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -307,7 +306,7 @@ async def test_smartstrip_device(hass: HomeAssistant):
|
|||||||
"""Moked SmartStrip class."""
|
"""Moked SmartStrip class."""
|
||||||
|
|
||||||
def get_sysinfo(self):
|
def get_sysinfo(self):
|
||||||
return SMARTSTRIPWITCH_DATA["sysinfo"]
|
return SMARTSTRIP_KP303_DATA["sysinfo"]
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tplink.common.Discover.discover"
|
"homeassistant.components.tplink.common.Discover.discover"
|
||||||
@ -315,9 +314,7 @@ async def test_smartstrip_device(hass: HomeAssistant):
|
|||||||
"homeassistant.components.tplink.common.SmartDevice._query_helper"
|
"homeassistant.components.tplink.common.SmartDevice._query_helper"
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.tplink.common.SmartPlug.get_sysinfo",
|
"homeassistant.components.tplink.common.SmartPlug.get_sysinfo",
|
||||||
return_value=SMARTSTRIPWITCH_DATA["sysinfo"],
|
return_value=SMARTSTRIP_KP303_DATA["sysinfo"],
|
||||||
), patch(
|
|
||||||
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup"
|
|
||||||
):
|
):
|
||||||
|
|
||||||
strip = SmartStrip("123.123.123.123")
|
strip = SmartStrip("123.123.123.123")
|
||||||
@ -326,16 +323,8 @@ async def test_smartstrip_device(hass: HomeAssistant):
|
|||||||
assert await async_setup_component(hass, tplink.DOMAIN, config)
|
assert await async_setup_component(hass, tplink.DOMAIN, config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.data.get(tplink.DOMAIN)
|
entities = hass.states.async_entity_ids(SWITCH_DOMAIN)
|
||||||
assert hass.data[tplink.DOMAIN].get(COORDINATORS)
|
assert len(entities) == 3
|
||||||
assert hass.data[tplink.DOMAIN][COORDINATORS].get(strip.mac)
|
|
||||||
assert isinstance(
|
|
||||||
hass.data[tplink.DOMAIN][COORDINATORS][strip.mac],
|
|
||||||
tplink.SmartPlugDataUpdateCoordinator,
|
|
||||||
)
|
|
||||||
data = hass.data[tplink.DOMAIN][COORDINATORS][strip.mac].data
|
|
||||||
assert data[CONF_ALIAS] == strip.sys_info["children"][0]["alias"]
|
|
||||||
assert data[CONF_DEVICE_ID] == "1"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_no_config_creates_no_entry(hass):
|
async def test_no_config_creates_no_entry(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user