Fix autodiscovery IP key and add error message for unsupported model
This commit is contained in:
parent
7f344d38bf
commit
01024d8e56
|
|
@ -41,19 +41,14 @@ async def async_setup(hass, entry) -> bool:
|
|||
return
|
||||
|
||||
hass_data = entry.data.copy()
|
||||
if device["gwId"] in hass_data[CONF_VACS] and device.get(CONF_IP_ADDRESS) is not None:
|
||||
if (
|
||||
hass_data[CONF_VACS][device["gwId"]]["ip_address"]
|
||||
!= device[CONF_IP_ADDRESS]
|
||||
):
|
||||
hass_data[CONF_VACS][device["gwId"]]["ip_address"] = device[
|
||||
CONF_IP_ADDRESS
|
||||
]
|
||||
if device["gwId"] in hass_data[CONF_VACS] and device.get("ip") is not None:
|
||||
if hass_data[CONF_VACS][device["gwId"]][CONF_IP_ADDRESS] != device["ip"]:
|
||||
hass_data[CONF_VACS][device["gwId"]][CONF_IP_ADDRESS] = device["ip"]
|
||||
hass.config_entries.async_update_entry(entry, data=hass_data)
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
_LOGGER.debug(
|
||||
"Updated ip address of {} to {}".format(
|
||||
device["gwId"], device[CONF_IP_ADDRESS]
|
||||
device["gwId"], device["ip"]
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
ERROR_MESSAGES = {
|
||||
"IP_ADDRESS": "IP Address not set",
|
||||
"CONNECTION_FAILED": "Connection to the vacuum failed",
|
||||
"UNSUPPORTED_MODEL": "This model is not supported",
|
||||
"no_error": "None",
|
||||
1:"Front bumper stuck",
|
||||
2:"Wheel stuck",
|
||||
|
|
|
|||
|
|
@ -58,7 +58,12 @@ from homeassistant.const import (
|
|||
from .const import CONF_VACS, DOMAIN
|
||||
|
||||
from .errors import getErrorMessage
|
||||
from .robovac import SUPPORTED_ROBOVAC_MODELS, RoboVac, RoboVacEntityFeature
|
||||
from .robovac import (
|
||||
SUPPORTED_ROBOVAC_MODELS,
|
||||
ModelNotSupportedException,
|
||||
RoboVac,
|
||||
RoboVacEntityFeature,
|
||||
)
|
||||
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||
|
||||
|
|
@ -107,7 +112,6 @@ async def async_setup_entry(
|
|||
for item in vacuums:
|
||||
item = vacuums[item]
|
||||
entity = RoboVacEntity(item)
|
||||
await entity.vacuum.async_connect()
|
||||
async_add_entities([entity], update_before_add=True)
|
||||
|
||||
|
||||
|
|
@ -249,14 +253,17 @@ class RoboVacEntity(StateVacuumEntity):
|
|||
self._attr_ip_address = item[CONF_IP_ADDRESS]
|
||||
self._attr_access_token = item[CONF_ACCESS_TOKEN]
|
||||
|
||||
self.vacuum = RoboVac(
|
||||
device_id=self.unique_id,
|
||||
host=self.ip_address,
|
||||
local_key=self.access_token,
|
||||
timeout=2,
|
||||
ping_interval=REFRESH_RATE,
|
||||
model_code=self.model_code[0:5],
|
||||
)
|
||||
try:
|
||||
self.vacuum = RoboVac(
|
||||
device_id=self.unique_id,
|
||||
host=self.ip_address,
|
||||
local_key=self.access_token,
|
||||
timeout=2,
|
||||
ping_interval=REFRESH_RATE,
|
||||
model_code=self.model_code[0:5],
|
||||
)
|
||||
except ModelNotSupportedException:
|
||||
self.error_code = "UNSUPPORTED_MODEL"
|
||||
|
||||
self._attr_supported_features = self.vacuum.getHomeAssistantFeatures()
|
||||
self._attr_robovac_supported = self.vacuum.getRoboVacFeatures()
|
||||
|
|
@ -280,6 +287,9 @@ class RoboVacEntity(StateVacuumEntity):
|
|||
|
||||
async def async_update(self):
|
||||
"""Synchronise state from the vacuum."""
|
||||
if self.error_code == "UNSUPPORTED_MODEL":
|
||||
return
|
||||
|
||||
if self.ip_address == "":
|
||||
self.error_code = "IP_ADDRESS"
|
||||
return
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
cryptography==41.0.3
|
||||
homeassistant==2023.8.4
|
||||
Requests==2.31.0
|
||||
setuptools==68.0.0
|
||||
voluptuous==0.13.1
|
||||
Loading…
Reference in New Issue