Skip to content

Commit

Permalink
Add the support of Aqara YuBa T1
Browse files Browse the repository at this point in the history
  • Loading branch information
niceboy committed Oct 18, 2023
1 parent 4238fde commit 58d9177
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions custom_components/aqara_gateway/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
'cover',
'light',
'remote',
'select',
'sensor',
'switch']

Expand Down
41 changes: 37 additions & 4 deletions custom_components/aqara_gateway/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,7 @@
'params': [
['3.51.85', None, 'occupancy', 'binary_sensor'],
['8.0.2115', None, 'detect_interval', None],
['4.1.85', None, 'monitoring_mode', None],
['4.2.85', None, 'reverted_mode', None],
['4.22.85', None, '4.22.85', None],
['14.47.85', None, 'approaching_distance', None],
['14.48.85', None, '14.48.85', None],
['14.49.85', None, '14.49.85', None],
['14.92.85', None, 'edge_region', None],
Expand All @@ -486,6 +483,9 @@
['14.56.85', None, 'detecting_region', None],
['13.21.85', None, 'occupancy_region', 'sensor'],
['13.27.85', None, 'movements', 'sensor'],
['4.1.85', None, 'monitoring_mode', 'select'],
['4.2.85', None, 'reverted_mode', 'select'],
['14.47.85', None, 'approaching_distance', 'select'],
]
}, {
# water leak sensor
Expand Down Expand Up @@ -865,7 +865,7 @@
'lumi.switch.b2nacn01': ["Aqara", "Double Wall Switch T1", "QBKG20LM"],
'lumi.switch.acn045': ["Aqara", "Double Wall Switch J1", ""],
'lumi.switch.acn049': ["Aqara", "Two-way Control module T2", "ZNQBKG39LM"],
'lumi.switch.acn047': ["Aqara", "Two-way Control module T2", "LLKZMK12LM"],
# 'lumi.switch.acn047': ["Aqara", "Two-way Control module T2", "LLKZMK12LM"],
'params': [
['4.1.85', 'channel_0', 'channel 1', 'switch'],
['4.2.85', 'channel_1', 'channel 2', 'switch'],
Expand Down Expand Up @@ -1249,6 +1249,20 @@
['4.24.85', 'auto_feed', 'auto_feed_switch', 'switch'],
['13.104.85', 'portion', 'portion', 'sensor']
]
}, {
'lumi.bhf_light.acn001': ["Aqara", "Smart Yuba T1", "ZNYB01LM"],
'params': [
['0.1.85', 'temperature', 'temperature', 'sensor'],
['1.8.85', 'temperature', 'target_temperature', 'sensor'],
['1.7.85', 'light_level', 'brightness', None],
['1.9.85', 'colour_temperature', 'color_temp', None],
['4.1.85', 'power_status', 'light', 'light'],
['4.21.85', 'switch', 'switch', 'switch'],
['8.0.2001', 'battery', 'battery', 'sensor'],
['14.35.85', None, 'fan_mode', 'select'],
['14.47.85', None, 'swing_mode', 'select'],
['14.51.85', None, 'operating_mode', 'select']
]
}]

DEVICES_MIOT = [{
Expand Down Expand Up @@ -1746,6 +1760,25 @@ def get_feature_suppported(zigbee_model: str) -> Optional[bool]:
feature['support_in_use'] = True
return feature

@staticmethod
def get_select_options(zigbee_model: str, attr: str) -> Optional[dict]:
if zigbee_model in ['lumi.bhf_light.acn001']:
if attr == 'fan_mode':
return {"Low": 0, "Middle": 1, "High": 2}
if attr == 'swing_mode':
return {"Enable": 0, "Disable": 1}
if attr == 'operating_mode':
return {"Warm": 0, "Dry": 3, "Fan": 4, "Exhaust": 5}
if zigbee_model in ['lumi.motion.ac01']:
if attr == 'monitoring_mode':
return {"Undirected": 0, "Left and right": 1}
if attr == 'approaching_distance':
return {"Near": 0, "Middle": 1, "Far": 2}
if attr == 'reverted_mode':
return {"Disable": 0, "Enable": 1}

return {"Off": 0, "On": 1}

@staticmethod
def gateway_illuminance_supported(model: str) -> Optional[bool]:
""" return the gateway illuminance supported """
Expand Down
69 changes: 69 additions & 0 deletions custom_components/aqara_gateway/select.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Support for Aqara Select."""

from homeassistant.core import callback
from homeassistant.components.select import SelectEntity
from homeassistant.helpers.restore_state import RestoreEntity

from . import DOMAIN, GatewayGenericDevice, gateway_state_property
from .core.gateway import Gateway

from .core.utils import Utils


async def async_setup_entry(hass, config_entry, async_add_entities):
""" Perform the setup for Xiaomi/Aqara devices. """
def setup(gateway: Gateway, device: dict, attr: str):
feature = Utils.get_feature_suppported(device["model"])
async_add_entities([
GatewaySelect(gateway, device, attr, feature)
])
aqara_gateway: Gateway = hass.data[DOMAIN][config_entry.entry_id]
aqara_gateway.add_setup('select', setup)


async def async_unload_entry(hass, entry):
# pylint: disable=unused-argument
""" unload entry """
return True


class GatewaySelect(GatewayGenericDevice, SelectEntity, RestoreEntity):
"""Representation of a Xiaomi/Aqara Select."""
# pylint: disable=unused-argument, too-many-instance-attributes
def __init__(
self,
gateway,
device,
attr,
feature
):
"""Initialize."""
self._model = device['model']
self.feature = feature
self._attr_current_option = None
self._attr_options = []
self._attr_state = None
self._map = {}
super().__init__(gateway, device, attr)

@callback
def async_restore_last_state(self, state: str, attrs: dict):
self._attr_current_option = state

async def async_added_to_hass(self) -> None:
"""Restore last state."""
await super().async_added_to_hass()
self._map = Utils.get_select_options(self.device["model"], self._attr)
self._attr_options = list(self._map.keys())

def update(self, data: dict = None):
"""update switch."""
for key, value in data.items():
if key == self._attr:
self._attr_current_option = list(
self._map.keys())[list(self._map.values()).index(data[self._attr])]
self.async_write_ha_state()

async def async_select_option(self, option: str):
""" set select option"""
self.gateway.send(self.device, {self._attr: self._map[option]})

0 comments on commit 58d9177

Please sign in to comment.