mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-21 01:39:36 +08:00
Compare commits
4 Commits
664787ca58
...
5b1d003bb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b1d003bb2 | ||
|
|
6069eaaba8 | ||
|
|
fd57e7c565 | ||
|
|
096b33f3c9 |
@ -85,6 +85,11 @@ SUPPORTED_PLATFORMS: list = [
|
|||||||
'water_heater',
|
'water_heater',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
UNSUPPORTED_MODELS: list = [
|
||||||
|
'chuangmi.ir.v2',
|
||||||
|
'xiaomi.router.rd03'
|
||||||
|
]
|
||||||
|
|
||||||
DEFAULT_CLOUD_SERVER: str = 'cn'
|
DEFAULT_CLOUD_SERVER: str = 'cn'
|
||||||
CLOUD_SERVERS: dict = {
|
CLOUD_SERVERS: dict = {
|
||||||
'cn': '中国大陆',
|
'cn': '中国大陆',
|
||||||
|
|||||||
@ -1354,6 +1354,11 @@ class MIoTClient:
|
|||||||
"""Update cloud devices.
|
"""Update cloud devices.
|
||||||
NOTICE: This function will operate the cloud_list
|
NOTICE: This function will operate the cloud_list
|
||||||
"""
|
"""
|
||||||
|
# MIoT cloud service may not publish the online state updating message
|
||||||
|
# for the BLE device. Assume that all BLE devices are online.
|
||||||
|
for did, info in cloud_list.items():
|
||||||
|
if did.startswith('blt.'):
|
||||||
|
info['online'] = True
|
||||||
for did, info in self._device_list_cache.items():
|
for did, info in self._device_list_cache.items():
|
||||||
if filter_dids and did not in filter_dids:
|
if filter_dids and did not in filter_dids:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -59,6 +59,7 @@ import aiohttp
|
|||||||
# pylint: disable=relative-beyond-top-level
|
# pylint: disable=relative-beyond-top-level
|
||||||
from .common import calc_group_id
|
from .common import calc_group_id
|
||||||
from .const import (
|
from .const import (
|
||||||
|
UNSUPPORTED_MODELS,
|
||||||
DEFAULT_OAUTH2_API_HOST,
|
DEFAULT_OAUTH2_API_HOST,
|
||||||
MIHOME_HTTP_API_TIMEOUT,
|
MIHOME_HTTP_API_TIMEOUT,
|
||||||
OAUTH2_AUTH_URL)
|
OAUTH2_AUTH_URL)
|
||||||
@ -573,6 +574,10 @@ class MIoTHttpClient:
|
|||||||
# were implemented.
|
# were implemented.
|
||||||
_LOGGER.info('ignore miwifi.* device, cloud, %s', did)
|
_LOGGER.info('ignore miwifi.* device, cloud, %s', did)
|
||||||
continue
|
continue
|
||||||
|
if model in UNSUPPORTED_MODELS:
|
||||||
|
_LOGGER.info('ignore unsupported model %s, cloud, %s',
|
||||||
|
model, did)
|
||||||
|
continue
|
||||||
device_infos[did] = {
|
device_infos[did] = {
|
||||||
'did': did,
|
'did': did,
|
||||||
'uid': device.get('uid', None),
|
'uid': device.get('uid', None),
|
||||||
|
|||||||
@ -1207,10 +1207,9 @@ class MIoTPropertyEntity(Entity):
|
|||||||
self._attr_available = miot_device.online
|
self._attr_available = miot_device.online
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
'new miot property entity, %s, %s, %s, %s, %s, %s, %s',
|
'new miot property entity, %s, %s, %s, %s, %s',
|
||||||
self.miot_device.name, self._attr_name, spec.platform,
|
self.miot_device.name, self._attr_name, spec.platform,
|
||||||
spec.device_class, self.entity_id, self._value_range,
|
spec.device_class, self.entity_id)
|
||||||
self._value_list)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> Optional[DeviceInfo]:
|
def device_info(self) -> Optional[DeviceInfo]:
|
||||||
|
|||||||
@ -68,7 +68,7 @@ from paho.mqtt.client import (
|
|||||||
|
|
||||||
# pylint: disable=relative-beyond-top-level
|
# pylint: disable=relative-beyond-top-level
|
||||||
from .common import MIoTMatcher
|
from .common import MIoTMatcher
|
||||||
from .const import MIHOME_MQTT_KEEPALIVE
|
from .const import UNSUPPORTED_MODELS, MIHOME_MQTT_KEEPALIVE
|
||||||
from .miot_error import MIoTErrorCode, MIoTMipsError
|
from .miot_error import MIoTErrorCode, MIoTMipsError
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -216,7 +216,7 @@ class _MipsClient(ABC):
|
|||||||
MQTT_INTERVAL_S = 1
|
MQTT_INTERVAL_S = 1
|
||||||
MIPS_QOS: int = 2
|
MIPS_QOS: int = 2
|
||||||
UINT32_MAX: int = 0xFFFFFFFF
|
UINT32_MAX: int = 0xFFFFFFFF
|
||||||
MIPS_RECONNECT_INTERVAL_MIN: float = 30
|
MIPS_RECONNECT_INTERVAL_MIN: float = 10
|
||||||
MIPS_RECONNECT_INTERVAL_MAX: float = 600
|
MIPS_RECONNECT_INTERVAL_MAX: float = 600
|
||||||
MIPS_SUB_PATCH: int = 300
|
MIPS_SUB_PATCH: int = 300
|
||||||
MIPS_SUB_INTERVAL: float = 1
|
MIPS_SUB_INTERVAL: float = 1
|
||||||
@ -641,6 +641,7 @@ class _MipsClient(ABC):
|
|||||||
if not self._mqtt.is_connected():
|
if not self._mqtt.is_connected():
|
||||||
return
|
return
|
||||||
self.log_info(f'mips connect, {flags}, {rc}, {props}')
|
self.log_info(f'mips connect, {flags}, {rc}, {props}')
|
||||||
|
self.__reset_reconnect_time()
|
||||||
self._mqtt_state = True
|
self._mqtt_state = True
|
||||||
self._internal_loop.call_soon(
|
self._internal_loop.call_soon(
|
||||||
self._on_mips_connect, rc, props)
|
self._on_mips_connect, rc, props)
|
||||||
@ -822,7 +823,7 @@ class _MipsClient(ABC):
|
|||||||
self._internal_loop.stop()
|
self._internal_loop.stop()
|
||||||
|
|
||||||
def __get_next_reconnect_time(self) -> float:
|
def __get_next_reconnect_time(self) -> float:
|
||||||
if self._mips_reconnect_interval == 0:
|
if self._mips_reconnect_interval < self.MIPS_RECONNECT_INTERVAL_MIN:
|
||||||
self._mips_reconnect_interval = self.MIPS_RECONNECT_INTERVAL_MIN
|
self._mips_reconnect_interval = self.MIPS_RECONNECT_INTERVAL_MIN
|
||||||
else:
|
else:
|
||||||
self._mips_reconnect_interval = min(
|
self._mips_reconnect_interval = min(
|
||||||
@ -830,6 +831,9 @@ class _MipsClient(ABC):
|
|||||||
self.MIPS_RECONNECT_INTERVAL_MAX)
|
self.MIPS_RECONNECT_INTERVAL_MAX)
|
||||||
return self._mips_reconnect_interval
|
return self._mips_reconnect_interval
|
||||||
|
|
||||||
|
def __reset_reconnect_time(self) -> None:
|
||||||
|
self._mips_reconnect_interval = 0
|
||||||
|
|
||||||
|
|
||||||
class MipsCloudClient(_MipsClient):
|
class MipsCloudClient(_MipsClient):
|
||||||
"""MIoT Pub/Sub Cloud Client."""
|
"""MIoT Pub/Sub Cloud Client."""
|
||||||
@ -1361,6 +1365,9 @@ class MipsLocalClient(_MipsClient):
|
|||||||
if name is None or urn is None or model is None:
|
if name is None or urn is None or model is None:
|
||||||
self.log_error(f'invalid device info, {did}, {info}')
|
self.log_error(f'invalid device info, {did}, {info}')
|
||||||
continue
|
continue
|
||||||
|
if model in UNSUPPORTED_MODELS:
|
||||||
|
self.log_info(f'unsupported model, {model}, {did}')
|
||||||
|
continue
|
||||||
device_list[did] = {
|
device_list[did] = {
|
||||||
'did': did,
|
'did': did,
|
||||||
'name': name,
|
'name': name,
|
||||||
|
|||||||
@ -44,9 +44,6 @@ urn:miot-spec-v2:device:motion-sensor:0000A014:xiaomi-pir1:
|
|||||||
services:
|
services:
|
||||||
- '1'
|
- '1'
|
||||||
- '5'
|
- '5'
|
||||||
urn:miot-spec-v2:device:router:0000A036:xiaomi-rd03:
|
|
||||||
services:
|
|
||||||
- '*'
|
|
||||||
urn:miot-spec-v2:device:thermostat:0000A031:tofan-wk01:
|
urn:miot-spec-v2:device:thermostat:0000A031:tofan-wk01:
|
||||||
services:
|
services:
|
||||||
- '2'
|
- '2'
|
||||||
|
|||||||
@ -141,12 +141,11 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
|
|||||||
continue
|
continue
|
||||||
self._mode_map = prop.value_list.to_map()
|
self._mode_map = prop.value_list.to_map()
|
||||||
self._attr_operation_list = list(self._mode_map.values())
|
self._attr_operation_list = list(self._mode_map.values())
|
||||||
self._attr_supported_features |= (
|
|
||||||
WaterHeaterEntityFeature.OPERATION_MODE)
|
|
||||||
self._prop_mode = prop
|
self._prop_mode = prop
|
||||||
if not self._attr_operation_list:
|
if not self._attr_operation_list:
|
||||||
self._attr_operation_list = [STATE_ON]
|
self._attr_operation_list = [STATE_ON]
|
||||||
self._attr_operation_list.append(STATE_OFF)
|
self._attr_operation_list.append(STATE_OFF)
|
||||||
|
self._attr_supported_features |= WaterHeaterEntityFeature.OPERATION_MODE
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn the water heater on."""
|
"""Turn the water heater on."""
|
||||||
@ -197,5 +196,5 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
|
|||||||
return STATE_OFF
|
return STATE_OFF
|
||||||
if not self._prop_mode and self.get_prop_value(prop=self._prop_on):
|
if not self._prop_mode and self.get_prop_value(prop=self._prop_on):
|
||||||
return STATE_ON
|
return STATE_ON
|
||||||
return self.get_map_value(map_=self._mode_map,
|
return (None if self._prop_mode is None else self.get_map_value(
|
||||||
key=self.get_prop_value(prop=self._prop_mode))
|
map_=self._mode_map, key=self.get_prop_value(prop=self._prop_mode)))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user