Skip to content

Commit

Permalink
Fix Aqara L1 Ceiling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 23, 2023
1 parent a1f5327 commit df280a1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
19 changes: 12 additions & 7 deletions custom_components/xiaomi_gateway3/core/converters/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@
MapConv("power_on_state", "select", mi="8.0.2030", map=BULB_MEMORY,
enabled=False),
],
}, {
"lumi.light.acn003": ["Aqara", "L1-350 Ceiling Light", "ZNXDD01LM"],
"spec": [
BoolConv("light", "light", mi="2.p.1"),
ZXiaomiBrightnessConv("brightness", mi="2.p.2", parent="light"),
ZXiaomiColorTempConv("color_temp", mi="2.p.3", parent="light"),
],
}, {
# light with brightness
"ikea.light.led1623g12": ["IKEA", "Bulb E27 1000 lm", "LED1623G12"],
Expand Down Expand Up @@ -984,6 +977,18 @@
BatteryConv("battery", "sensor", mi="2.p.1"), # voltage
MapConv("battery_low", "binary_sensor", mi="4.p.1", map=BATTERY_LOW, enabled=False)
]
}, {
# https://home.miot-spec.com/spec/lumi.light.acn003
"lumi.light.acn003": ["Aqara", "L1-350 Ceiling Light", "ZNXDD01LM"],
"spec": [
Converter("light", "light", mi="2.p.1"),
BrightnessConv("brightness", mi="2.p.2", parent="light"),
ColorTempKelvin("color_temp", mi="2.p.3", parent="light"),
MapConv("mode", "select", mi="2.p.4", map={
0: "day", 1: "reading", 2: "warm", 3: "tv", 4: "night"
}),
Converter("power_on_state", "switch", mi="3.p.2", enabled=False), # bool
],
}]

########################################################################################
Expand Down
49 changes: 46 additions & 3 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

from homeassistant.components.sensor import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.config import DATA_CUSTOMIZE
from homeassistant.core import HomeAssistant, EventBus

from custom_components.xiaomi_gateway3.binary_sensor import XiaomiBinarySensor
from custom_components.xiaomi_gateway3.climate import AqaraE1
Expand All @@ -21,10 +22,13 @@


class Hass(HomeAssistant):
def __new__(cls):
return HomeAssistant.__new__(cls, "")

def __init__(self):
asyncio.get_running_loop = lambda: asyncio.new_event_loop()
HomeAssistant.__init__(self)
self.bus.async_fire = self.async_fire
EventBus.async_fire = self.async_fire
HomeAssistant.__init__(self, "")
self.events = []

def async_fire(self, *args, **kwargs):
Expand Down Expand Up @@ -186,3 +190,42 @@ def test_number():
number = XiaomiNumber(gw, device, conv)
number.hass = Hass()
number.async_write_ha_state()


def test_celling():
# https://github.com/AlexxIT/XiaomiGateway3/issues/1209
gw = XGateway("", "")
device = XDevice(ZIGBEE, "lumi.light.acn003", ZDID, ZMAC, ZNWK)
device.setup_converters()
device.available = True

conv = next(conv for conv in device.converters if conv.attr == "light")
light = XiaomiZigbeeLight(gw, device, conv)
light.hass = Hass()
light.async_write_ha_state()

light.hass.data[DATA_CUSTOMIZE] = {light.entity_id: {}}

light.hass.loop.run_until_complete(light.async_turn_on())

assert gw.mqtt.pub_buffer[0] == [
"zigbee/recv",
{
"cmd": "write",
"did": "lumi.112233aabbcc",
"mi_spec": [{"piid": 1, "siid": 2, "value": True}],
},
False,
]

light.hass.loop.run_until_complete(light.async_turn_on(brightness=100))

assert gw.mqtt.pub_buffer[1] == [
"zigbee/recv",
{
"cmd": "write",
"did": "lumi.112233aabbcc",
"mi_spec": [{"piid": 2, "siid": 2, "value": 39}],
},
False,
]

0 comments on commit df280a1

Please sign in to comment.