Xiaomi MiIO Vacuum: Use a unique data key per domain (#12743)
* Use a unique data key per domain. * Tests fixed.
This commit is contained in:
parent
a0eca9c6d1
commit
222748dfbf
2 changed files with 9 additions and 7 deletions
|
@ -25,7 +25,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'Xiaomi Vacuum cleaner'
|
DEFAULT_NAME = 'Xiaomi Vacuum cleaner'
|
||||||
ICON = 'mdi:roomba'
|
ICON = 'mdi:roomba'
|
||||||
PLATFORM = 'xiaomi_miio'
|
DATA_KEY = 'vacuum.xiaomi_miio'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
@ -88,8 +88,8 @@ SUPPORT_XIAOMI = SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PAUSE | \
|
||||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the Xiaomi vacuum cleaner robot platform."""
|
"""Set up the Xiaomi vacuum cleaner robot platform."""
|
||||||
from miio import Vacuum
|
from miio import Vacuum
|
||||||
if PLATFORM not in hass.data:
|
if DATA_KEY not in hass.data:
|
||||||
hass.data[PLATFORM] = {}
|
hass.data[DATA_KEY] = {}
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
@ -100,7 +100,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
vacuum = Vacuum(host, token)
|
vacuum = Vacuum(host, token)
|
||||||
|
|
||||||
mirobo = MiroboVacuum(name, vacuum)
|
mirobo = MiroboVacuum(name, vacuum)
|
||||||
hass.data[PLATFORM][host] = mirobo
|
hass.data[DATA_KEY][host] = mirobo
|
||||||
|
|
||||||
async_add_devices([mirobo], update_before_add=True)
|
async_add_devices([mirobo], update_before_add=True)
|
||||||
|
|
||||||
|
@ -112,10 +112,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
if key != ATTR_ENTITY_ID}
|
if key != ATTR_ENTITY_ID}
|
||||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
||||||
if entity_ids:
|
if entity_ids:
|
||||||
target_vacuums = [vac for vac in hass.data[PLATFORM].values()
|
target_vacuums = [vac for vac in hass.data[DATA_KEY].values()
|
||||||
if vac.entity_id in entity_ids]
|
if vac.entity_id in entity_ids]
|
||||||
else:
|
else:
|
||||||
target_vacuums = hass.data[PLATFORM].values()
|
target_vacuums = hass.data[DATA_KEY].values()
|
||||||
|
|
||||||
update_tasks = []
|
update_tasks = []
|
||||||
for vacuum in target_vacuums:
|
for vacuum in target_vacuums:
|
||||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.components.vacuum.xiaomi_miio import (
|
||||||
ATTR_DO_NOT_DISTURB_START, ATTR_DO_NOT_DISTURB_END, ATTR_ERROR,
|
ATTR_DO_NOT_DISTURB_START, ATTR_DO_NOT_DISTURB_END, ATTR_ERROR,
|
||||||
ATTR_MAIN_BRUSH_LEFT, ATTR_SIDE_BRUSH_LEFT, ATTR_FILTER_LEFT,
|
ATTR_MAIN_BRUSH_LEFT, ATTR_SIDE_BRUSH_LEFT, ATTR_FILTER_LEFT,
|
||||||
ATTR_CLEANING_COUNT, ATTR_CLEANED_TOTAL_AREA, ATTR_CLEANING_TOTAL_TIME,
|
ATTR_CLEANING_COUNT, ATTR_CLEANED_TOTAL_AREA, ATTR_CLEANING_TOTAL_TIME,
|
||||||
CONF_HOST, CONF_NAME, CONF_TOKEN, PLATFORM,
|
CONF_HOST, CONF_NAME, CONF_TOKEN,
|
||||||
SERVICE_MOVE_REMOTE_CONTROL, SERVICE_MOVE_REMOTE_CONTROL_STEP,
|
SERVICE_MOVE_REMOTE_CONTROL, SERVICE_MOVE_REMOTE_CONTROL_STEP,
|
||||||
SERVICE_START_REMOTE_CONTROL, SERVICE_STOP_REMOTE_CONTROL)
|
SERVICE_START_REMOTE_CONTROL, SERVICE_STOP_REMOTE_CONTROL)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -24,6 +24,8 @@ from homeassistant.const import (
|
||||||
STATE_ON)
|
STATE_ON)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
PLATFORM = 'xiaomi_miio'
|
||||||
|
|
||||||
# calls made when device status is requested
|
# calls made when device status is requested
|
||||||
status_calls = [mock.call.Vacuum().status(),
|
status_calls = [mock.call.Vacuum().status(),
|
||||||
mock.call.Vacuum().consumable_status(),
|
mock.call.Vacuum().consumable_status(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue