fix: merge conflicts

This commit is contained in:
LiShuzhen 2025-12-16 08:36:31 +08:00
commit 9a54a5ac2b
5 changed files with 53 additions and 37 deletions

View File

@ -430,15 +430,16 @@ class FeatureState(MIoTServiceEntity, MediaPlayerEntity):
elif item.name in {'pause', 'paused'}: elif item.name in {'pause', 'paused'}:
self._playing_state_map[ self._playing_state_map[
item.value] = MediaPlayerState.PAUSED item.value] = MediaPlayerState.PAUSED
self._prop_playing_state = prop self._prop_playing_state = prop
@property @property
def state(self) -> Optional[MediaPlayerState]: def state(self) -> Optional[MediaPlayerState]:
"""The current state.""" """The current state."""
return (self.get_map_value(map_=self._playing_state_map, current_state = self.get_prop_value(
key=self.get_prop_value( prop=self._prop_playing_state) if self._prop_playing_state else None
prop=self._prop_playing_state)) return (MediaPlayerState.ON if
if self._prop_playing_state else MediaPlayerState.ON) (current_state is None) else self.get_map_value(
map_=self._playing_state_map, key=current_state))
class WifiSpeaker(FeatureVolumeSet, FeatureVolumeMute, FeaturePlay, class WifiSpeaker(FeatureVolumeSet, FeatureVolumeMute, FeaturePlay,

View File

@ -79,6 +79,12 @@ from .miot_i18n import MIoTI18n
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
REFRESH_PROPS_DELAY = 0.2
REFRESH_PROPS_RETRY_DELAY = 3
REFRESH_CLOUD_DEVICES_DELAY = 6
REFRESH_CLOUD_DEVICES_RETRY_DELAY = 60
REFRESH_GATEWAY_DEVICES_DELAY = 3
@dataclass @dataclass
class MIoTClientSub: class MIoTClientSub:
"""MIoT client subscription.""" """MIoT client subscription."""
@ -717,7 +723,7 @@ class MIoTClient:
if self._refresh_props_timer: if self._refresh_props_timer:
return return
self._refresh_props_timer = self._main_loop.call_later( self._refresh_props_timer = self._main_loop.call_later(
0.2, lambda: self._main_loop.create_task( REFRESH_PROPS_DELAY, lambda: self._main_loop.create_task(
self.__refresh_props_handler())) self.__refresh_props_handler()))
async def get_prop_async(self, did: str, siid: int, piid: int) -> Any: async def get_prop_async(self, did: str, siid: int, piid: int) -> Any:
@ -1433,9 +1439,19 @@ class MIoTClient:
async def __refresh_cloud_devices_async(self) -> None: async def __refresh_cloud_devices_async(self) -> None:
_LOGGER.debug( _LOGGER.debug(
'refresh cloud devices, %s, %s', self._uid, self._cloud_server) 'refresh cloud devices, %s, %s', self._uid, self._cloud_server)
self._refresh_cloud_devices_timer = None if self._refresh_cloud_devices_timer:
result = await self._http.get_devices_async( self._refresh_cloud_devices_timer.cancel()
home_ids=list(self._entry_data.get('home_selected', {}).keys())) self._refresh_cloud_devices_timer = None
try:
result = await self._http.get_devices_async(
home_ids=list(self._entry_data.get('home_selected', {}).keys()))
except Exception as err: # pylint: disable=broad-exception-caught
_LOGGER.error('refresh cloud devices failed, %s', err)
self._refresh_cloud_devices_timer = self._main_loop.call_later(
REFRESH_CLOUD_DEVICES_RETRY_DELAY,
lambda: self._main_loop.create_task(
self.__refresh_cloud_devices_async()))
return
if not result and 'devices' not in result: if not result and 'devices' not in result:
self.__show_client_error_notify( self.__show_client_error_notify(
message=self._i18n.translate( message=self._i18n.translate(
@ -1481,17 +1497,11 @@ class MIoTClient:
_LOGGER.debug( _LOGGER.debug(
'request refresh cloud devices, %s, %s', 'request refresh cloud devices, %s, %s',
self._uid, self._cloud_server) self._uid, self._cloud_server)
if immediately: delay_sec : int = 0 if immediately else REFRESH_CLOUD_DEVICES_DELAY
if self._refresh_cloud_devices_timer:
self._refresh_cloud_devices_timer.cancel()
self._refresh_cloud_devices_timer = self._main_loop.call_later(
0, lambda: self._main_loop.create_task(
self.__refresh_cloud_devices_async()))
return
if self._refresh_cloud_devices_timer: if self._refresh_cloud_devices_timer:
return self._refresh_cloud_devices_timer.cancel()
self._refresh_cloud_devices_timer = self._main_loop.call_later( self._refresh_cloud_devices_timer = self._main_loop.call_later(
6, lambda: self._main_loop.create_task( delay_sec, lambda: self._main_loop.create_task(
self.__refresh_cloud_devices_async())) self.__refresh_cloud_devices_async()))
@final @final
@ -1615,7 +1625,8 @@ class MIoTClient:
return return
self._mips_local_state_changed_timers[group_id] = ( self._mips_local_state_changed_timers[group_id] = (
self._main_loop.call_later( self._main_loop.call_later(
3, lambda: self._main_loop.create_task( REFRESH_GATEWAY_DEVICES_DELAY,
lambda: self._main_loop.create_task(
self.__refresh_gw_devices_with_group_id_async( self.__refresh_gw_devices_with_group_id_async(
group_id=group_id)))) group_id=group_id))))
@ -1769,7 +1780,7 @@ class MIoTClient:
self._refresh_props_retry_count = 0 self._refresh_props_retry_count = 0
if self._refresh_props_list: if self._refresh_props_list:
self._refresh_props_timer = self._main_loop.call_later( self._refresh_props_timer = self._main_loop.call_later(
0.2, lambda: self._main_loop.create_task( REFRESH_PROPS_DELAY, lambda: self._main_loop.create_task(
self.__refresh_props_handler())) self.__refresh_props_handler()))
else: else:
self._refresh_props_timer = None self._refresh_props_timer = None
@ -1788,7 +1799,7 @@ class MIoTClient:
_LOGGER.info( _LOGGER.info(
'refresh props failed, retry, %s', self._refresh_props_retry_count) 'refresh props failed, retry, %s', self._refresh_props_retry_count)
self._refresh_props_timer = self._main_loop.call_later( self._refresh_props_timer = self._main_loop.call_later(
3, lambda: self._main_loop.create_task( REFRESH_PROPS_RETRY_DELAY, lambda: self._main_loop.create_task(
self.__refresh_props_handler())) self.__refresh_props_handler()))
@final @final

View File

@ -519,15 +519,12 @@ class _MipsClient(ABC):
if not self._mqtt or not self._mqtt.is_connected(): if not self._mqtt or not self._mqtt.is_connected():
self.log_error(f'mips sub when not connected, {topic}') self.log_error(f'mips sub when not connected, {topic}')
return return
try:
if topic not in self._mips_sub_pending_map: if topic not in self._mips_sub_pending_map:
self._mips_sub_pending_map[topic] = 0 self._mips_sub_pending_map[topic] = 0
if not self._mips_sub_pending_timer: if not self._mips_sub_pending_timer:
self._mips_sub_pending_timer = self._internal_loop.call_later( self._mips_sub_pending_timer = self._internal_loop.call_later(
0.01, self.__mips_sub_internal_pending_handler, topic) 0.01, self.__mips_sub_internal_pending_handler, topic)
except Exception as err: # pylint: disable=broad-exception-caught
# Catch all exception
self.log_error(f'mips sub internal error, {topic}. {err}')
@final @final
def _mips_unsub_internal(self, topic: str) -> None: def _mips_unsub_internal(self, topic: str) -> None:
@ -736,11 +733,16 @@ class _MipsClient(ABC):
self.log_error(f'retry mips sub internal error, {topic}') self.log_error(f'retry mips sub internal error, {topic}')
continue continue
subbed_count += 1 subbed_count += 1
result, mid = self._mqtt.subscribe(topic, qos=self.MIPS_QOS) result = mid = None
if result == MQTT_ERR_SUCCESS: try:
self._mips_sub_pending_map.pop(topic) result, mid = self._mqtt.subscribe(topic, qos=self.MIPS_QOS)
self.log_debug(f'mips sub internal success, {topic}') if result == MQTT_ERR_SUCCESS:
continue self._mips_sub_pending_map.pop(topic)
self.log_debug(f'mips sub internal success, {topic}')
continue
except Exception as err: # pylint: disable=broad-exception-caught
# Catch all exception
self.log_error(f'mips sub internal error, {topic}. {err}')
self._mips_sub_pending_map[topic] = count+1 self._mips_sub_pending_map[topic] = count+1
self.log_error( self.log_error(
f'retry mips sub internal, {count}, {topic}, {result}, {mid}') f'retry mips sub internal, {count}, {topic}, {result}, {mid}')

View File

@ -291,7 +291,7 @@ class MIoTNetwork:
return self._main_loop.time() - start_ts return self._main_loop.time() - start_ts
return self._DETECT_TIMEOUT return self._DETECT_TIMEOUT
except Exception as err: # pylint: disable=broad-exception-caught except Exception as err: # pylint: disable=broad-exception-caught
print(err) _LOGGER.debug('ping error, %s',err)
return self._DETECT_TIMEOUT return self._DETECT_TIMEOUT
async def __http_async(self, url: str) -> float: async def __http_async(self, url: str) -> float:

View File

@ -325,10 +325,12 @@ SPEC_DEVICE_TRANS_MAP: dict = {
}, },
'play-control': { 'play-control': {
'required': { 'required': {
'properties': {
'playing-state': {'read'}
},
'actions': {'play'} 'actions': {'play'}
}, },
'optional': { 'optional': {
'properties': {'playing-state'},
'actions': {'pause', 'stop', 'next', 'previous'} 'actions': {'pause', 'stop', 'next', 'previous'}
} }
} }