Skip to content

Commit

Permalink
Add Aqara Wall Switch US support.
Browse files Browse the repository at this point in the history
  • Loading branch information
niceboy committed Jun 7, 2021
1 parent 2b6e792 commit 8373642
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
4 changes: 2 additions & 2 deletions custom_components/aqara_gateway/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _set_state(self, state):
self._shell.set_prop('persist.app.arming_guard', value)
self._shell.run_basis_cli(command)
self._state = ALARM_STATES[state]
self.async_write_ha_state()
self.schedule_update_ha_state()

def _get_state(self):
self._state = STATE_ALARM_DISARMED
Expand All @@ -129,4 +129,4 @@ def _get_state(self):
def update(self, *args):
"""Update the alarm status."""
self._get_state()
self.async_write_ha_state()
self.schedule_update_ha_state()
2 changes: 1 addition & 1 deletion custom_components/aqara_gateway/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def update(self, data: dict = None):
else:
self._state = not value

self.async_write_ha_state()
self.schedule_update_ha_state()


class GatewayMotionSensor(GatewayBinarySensor):
Expand Down
14 changes: 9 additions & 5 deletions custom_components/aqara_gateway/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, hass, host: str, config: dict, **options):
self._info_ts = None
self._gateway_did = ''
self._model = None # for fast access
self._cloud = 'aiot' # for fast access

@property
def device(self):
Expand Down Expand Up @@ -249,9 +250,11 @@ def _get_devices(self, shell: TelnetShell):

value = json.loads(raw)
dev_info = value.get("devInfo", 'null') or []
self._cloud = shell.get_prop("persist.sys.cloud")

for dev in dev_info:
model = dev['model']
desc = Utils.get_device(model)
desc = Utils.get_device(model, self._cloud)
# skip unknown model
if desc is None:
self.debug("{} has an unsupported model: {}".format(
Expand Down Expand Up @@ -279,7 +282,7 @@ def setup_devices(self, devices: list):
for device in devices:
timeout = 300
if device['type'] in ('gateway', 'zigbee'):
desc = Utils.get_device(device['model'])
desc = Utils.get_device(device['model'], self._cloud)
if not desc:
self.debug("Unsupported model: {}".format(device))
continue
Expand Down Expand Up @@ -458,7 +461,7 @@ def _process_devices_info(self, prop, value):
dev_info = value.get("devInfo", 'null') or []
for dev in dev_info:
model = dev['model']
desc = Utils.get_device(model)
desc = Utils.get_device(model, self._cloud)
# skip unknown model
if desc is None:
self.debug("{} has an unsupported modell: {}".format(
Expand Down Expand Up @@ -661,8 +664,9 @@ def send(self, device: dict, data: dict):
val = bool(val)
key = next(
p[0] for p in device['mi_spec'] if p[2] == key)
params.append(
{'siid': key[0], 'piid': key[1], 'value': val})
params.append({
'siid': int(key[0]), 'piid': int(key[2]), 'value': val
})

payload['mi_spec'] = params
else:
Expand Down
96 changes: 92 additions & 4 deletions custom_components/aqara_gateway/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
]
}, {
'lumi.switch.b2lacn02': ["Aqara", "Double Wall Switch D1", "QBKG22LM"],
'lumi.switch.b2laus01': ["Aqara", "Double Wall Switch US", "WS-USC02"],
'lumi.switch.n2acn1': ["Aqara", "Double Wall Switch H1 PRO", "QBKG31LM"], # @miniknife88
'params': [
['4.1.85', 'channel_0', 'channel 1', 'switch'],
Expand Down Expand Up @@ -471,7 +470,7 @@
['3.2', '3.2', 'power', 'sensor'],
# ['5.7', '5.7', 'voltage', 'sensor'],
]
}, {
}, {
'lumi.motion.agl04': ["Aqara", "Precision Motion Sensor", "RTCGQ13LM"],
'mi_spec': [
[None, None, 'motion', 'binary_sensor'],
Expand Down Expand Up @@ -500,6 +499,88 @@
]
}]

DEVICES_AIOT = [{
'lumi.switch.b1laus01': ["Aqara", "Single Wall Switch US", "WS-USC01"],
'params': [
['4.1.85', 'channel_0', 'switch', 'switch'], # or neutral_0?
['13.1.85', None, 'button', None],
[None, None, 'switch', 'binary_sensor'],
]
}, {
'lumi.switch.b2laus01': ["Aqara", "Double Wall Switch US", "WS-USC02"],
'params': [
['4.1.85', 'channel_0', 'channel 1', 'switch'],
['4.2.85', 'channel_1', 'channel 2', 'switch'],
['13.1.85', None, 'button_1', None],
['13.2.85', None, 'button_2', None],
['13.5.85', None, 'button_both', None],
[None, None, 'switch', 'binary_sensor'],
]
}, {
'lumi.switch.b1naus01': ["Aqara", "Single Wall Switch US", "WS-USC03"],
'params': [
['0.12.85', 'load_power', 'power', 'sensor'],
['0.13.85', None, 'consumption', 'sensor'],
['4.1.85', 'neutral_0', 'switch', 'switch'], # or channel_0?
['13.1.85', None, 'button', None],
[None, None, 'switch', 'binary_sensor'],
]
}, {
'lumi.switch.b2naus01': ["Aqara", "Double Wall Switch US", "WS-USC04"],
'params': [
['0.11.85', 'load_voltage', 'power', None],
['0.12.85', 'load_power', 'power', 'sensor'],
['0.13.85', None, 'consumption', 'sensor'],
['4.1.85', 'channel_0', 'channel 1', 'switch'],
['4.2.85', 'channel_1', 'channel 2', 'switch'],
['13.1.85', None, 'button_1', None],
['13.2.85', None, 'button_2', None],
['13.5.85', None, 'button_both', None],
[None, None, 'switch', 'binary_sensor'],
]
}]

DEVICES_MIOT = [{
'lumi.switch.b1laus01': ["Aqara", "Single Wall Switch US", "WS-USC01"],
'mi_spec': [
['2.1', '2.1', 'switch', 'switch'],
['13.1.85', None, 'button', None],
[None, None, 'switch', 'binary_sensor'],
]
}, {
'lumi.switch.b2laus01': ["Aqara", "Single Wall Switch US", "WS-USC02"],
'mi_spec': [
['2.1', '2.1', 'switch', 'switch'],
['6.1', None, 'button: 1', None],
['6.2', None, 'button: 2', None],
[None, None, 'action', 'sensor'],
]
}, {
'lumi.switch.b1naus01': ["Aqara", "Single Wall Switch US", "WS-USC03"],
'mi_spec': [
['2.1', '2.1', 'switch', 'switch'],
['4.1', None, 'consumption', None],
['4.2', 'load_power', 'power', 'sensor'],
['6.1', None, 'button: 1', None],
['6.2', None, 'button: 2', None],
[None, None, 'action', 'sensor'],
]
}, {
'lumi.switch.b2naus01': ["Aqara", "Double Wall Switch US", "WS-USC04"],
'mi_spec': [
['2.1', '2.1', 'channel 1', 'switch'],
['3.1', '3.1', 'channel 2', 'switch'],
['4.1', None, 'consumption', None],
['4.2', 'load_power', 'power', 'sensor'],
['7.1', None, 'button_1: 1', None],
['7.2', None, 'button_1: 2', None],
['8.1', None, 'button_2: 1', None],
['8.2', None, 'button_2: 2', None],
['9.1', None, 'button_both: 4', None],
[None, None, 'action', 'sensor'],
]
}]

GLOBAL_PROP = {
'0.11.85': 'load_voltage',
'0.12.85': 'load_power',
Expand Down Expand Up @@ -588,13 +669,20 @@
class Utils:
""" gateway utils """
@staticmethod
def get_device(zigbee_model: str) -> Optional[dict]:
def get_device(zigbee_model: str, cloud: str) -> Optional[dict]:
""" get device """
# the model has an extra tail when added
if re.match(r'\.v(\d)', zigbee_model[-3:]):
zigbee_model = zigbee_model[:-3]

for device in DEVICES:
devices = []
devices.extend(DEVICES)
if cloud and cloud == "aiot":
devices.extend(DEVICES_AIOT)
elif cloud and cloud == "miot":
devices.extend(DEVICES_MIOT)

for device in devices:
if zigbee_model in device:
desc = device[zigbee_model]
return {
Expand Down

0 comments on commit 8373642

Please sign in to comment.