1 """Code to handle a Xiaomi Gateway."""
5 from construct.core
import ChecksumError
6 from micloud
import MiCloud
7 from micloud.micloudexception
import MiCloudAccessDenied
8 from miio
import DeviceException, gateway
9 from miio.gateway.gateway
import GATEWAY_MODEL_EU
14 CONF_CLOUD_SUBDEVICES,
20 _LOGGER = logging.getLogger(__name__)
24 """Class to async connect to a Xiaomi Gateway."""
27 """Initialize the entity."""
41 """Return the class containing all connections to the gateway."""
46 """Return the class containing gateway info."""
50 """Connect to the Xiaomi Gateway."""
51 _LOGGER.debug(
"Initializing with host %s (token %s...)", host, token[:5])
53 self.
_host_host = host
70 """Connect the gateway in a way that can called by async_add_executor_job."""
75 except DeviceException
as error:
76 if isinstance(error.__cause__, ChecksumError):
80 f
"DeviceException during setup of xiaomi gateway with host {self._host}"
89 except DeviceException
as error:
92 "DeviceException during getting subdevices of xiaomi gateway"
93 " with host %s, trying cloud to obtain subdevices: %s"
108 "Missing cloud credentials in Xiaomi Miio configuration"
113 if not miio_cloud.login():
116 "Failed to login to Xiaomi Miio Cloud during setup of"
117 f
" Xiaomi gateway with host {self._host}"
120 devices_raw = miio_cloud.get_devices(self.
_cloud_country_cloud_country)
122 except MiCloudAccessDenied
as error:
124 "Could not login to Xiaomi Miio Cloud, check the credentials"
126 except DeviceException
as error:
128 "DeviceException during setup of xiaomi gateway with host"
def __init__(self, hass, config_entry)
def async_connect_gateway(self, host, token)
def connect_gateway(self)
list[tuple[str, str]] discover_devices(int device_id)