Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into v1
Browse files Browse the repository at this point in the history
# Conflicts:
#	custom_components/xiaomi_miot/core/xiaomi_cloud.py
  • Loading branch information
al-one committed Nov 14, 2024
2 parents a8c9b9a + f1526ea commit 7f8da61
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
17 changes: 5 additions & 12 deletions custom_components/xiaomi_miot/alarm_control_panel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
"""Support alarm_control_panel entity for Xiaomi Miot."""
import logging

from homeassistant.const import (
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMED_NIGHT,
STATE_ALARM_DISARMED,
STATE_ALARM_TRIGGERED,
)
from homeassistant.components.alarm_control_panel import (
DOMAIN as ENTITY_DOMAIN,
AlarmControlPanelEntity,
Expand Down Expand Up @@ -91,17 +84,17 @@ def update_state(self):
if des is not None:
des = f'{des}'.lower()
if 'basic' in des:
self._attr_state = STATE_ALARM_DISARMED
self._attr_state = AlarmControlPanelState.DISARMED
elif 'home' in des:
self._attr_state = STATE_ALARM_ARMED_HOME
self._attr_state = AlarmControlPanelState.ARMED_HOME
elif 'away' in des:
self._attr_state = STATE_ALARM_ARMED_AWAY
self._attr_state = AlarmControlPanelState.ARMED_AWAY
elif 'sleep' in des:
self._attr_state = STATE_ALARM_ARMED_NIGHT
self._attr_state = AlarmControlPanelState.ARMED_NIGHT
if self._is_mgl03:
val = self._state_attrs.get('arming.alarm')
if val:
self._attr_state = STATE_ALARM_TRIGGERED
self._attr_state = AlarmControlPanelState.TRIGGERED
return self._attr_state

def set_arm_mode(self, mode):
Expand Down
18 changes: 18 additions & 0 deletions custom_components/xiaomi_miot/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ class CameraState(StrEnum):
from homeassistant.core_config import DATA_CUSTOMIZE
except (ModuleNotFoundError, ImportError):
from homeassistant.helpers.entity import DATA_CUSTOMIZE

try:
# hass 2024.11
from homeassistant.components.alarm_control_panel import AlarmControlPanelState
except (ModuleNotFoundError, ImportError):
class AlarmControlPanelState(StrEnum):
"""Alarm control panel entity states."""

DISARMED = "disarmed"
ARMED_HOME = "armed_home"
ARMED_AWAY = "armed_away"
ARMED_NIGHT = "armed_night"
ARMED_VACATION = "armed_vacation"
ARMED_CUSTOM_BYPASS = "armed_custom_bypass"
PENDING = "pending"
ARMING = "arming"
DISARMING = "disarming"
TRIGGERED = "triggered"
8 changes: 5 additions & 3 deletions custom_components/xiaomi_miot/core/xiaomi_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ async def async_check_auth(self, notify=False):
}
try:
rdt = await self.async_request_api(api, dat, method='POST') or {}
nid = f'xiaomi-miot-auth-warning-{self.user_id}'
eno = rdt.get('code', 0)
msg = rdt.get('message', '')
if not (eno == 3 or msg == 'auth err'):
if not (eno in [2, 3] or 'auth err' in msg):
return True
except requests.exceptions.ConnectionError:
return None
except requests.exceptions.Timeout:
return None
# auth err
_LOGGER.info('Xiaomi auth failed, try relogin. %s', rdt)
nid = f'xiaomi-miot-auth-warning-{self.user_id}'
if await self.async_relogin():
persistent_notification.dismiss(self.hass, nid)
return True
Expand Down Expand Up @@ -438,7 +438,7 @@ async def async_get_homerooms(self, renew=False):
return dat.get('homes') or []

async def async_get_beaconkey(self, did):
dat = {'did': did or self.miot_did, 'pdid': 1}
dat = {'did': did, 'pdid': 1}
rdt = await self.async_request_api('v2/device/blt_get_beaconkey', dat) or {}
return rdt.get('result')

Expand Down Expand Up @@ -473,6 +473,7 @@ async def async_relogin(self):

def _logout(self):
self.service_token = None
self.async_session = None

def _login_request(self, captcha=None):
self._init_session(True)
Expand Down Expand Up @@ -570,6 +571,7 @@ def _login_step3(self, location):
service_token = response.cookies.get('serviceToken')
if service_token:
self.service_token = service_token
self.async_session = None
else:
err = {
'location': location,
Expand Down

0 comments on commit 7f8da61

Please sign in to comment.