Skip to content

Commit 27df906

Browse files
committed
Fix door sensor
1 parent e5503df commit 27df906

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

custom_components/xiaomi_gateway3/binary_sensor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
_LOGGER = logging.getLogger(__name__)
99

10+
DEVICE_CLASS = {
11+
'contact': 'door'
12+
}
13+
1014

1115
async def async_setup_entry(hass, config_entry, async_add_entities):
1216
def setup(gateway: Gateway3, device: dict, attr: str):
@@ -23,7 +27,7 @@ def is_on(self):
2327

2428
@property
2529
def device_class(self):
26-
return self._attr
30+
return DEVICE_CLASS.get(self._attr, self._attr)
2731

2832
def update(self, data: dict = None):
2933
if self._attr not in data:

custom_components/xiaomi_gateway3/gateway3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def _get_devices1(self) -> Optional[list]:
130130
for k, v in data.items():
131131
if k in ('temperature', 'humidity'):
132132
data[k] = v / 100.0
133-
elif v == 'on':
133+
elif v in ('on', 'open'):
134134
data[k] = 1
135-
elif v == 'off':
135+
elif v in ('off', 'close'):
136136
data[k] = 0
137137

138138
device['init'] = data
@@ -225,8 +225,8 @@ def _enable_mqtt(self):
225225

226226
def on_connect(self, client, userdata, flags, rc):
227227
_LOGGER.debug(f"{self.host} | MQTT connected")
228-
# self.mqtt.subscribe('#')
229-
self.mqtt.subscribe('zigbee/send')
228+
self.mqtt.subscribe('#')
229+
# self.mqtt.subscribe('zigbee/send')
230230

231231
def on_disconnect(self, client, userdata, rc):
232232
_LOGGER.debug(f"{self.host} | MQTT disconnected")

custom_components/xiaomi_gateway3/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535

3636
# https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/devices.js#L390
37+
# https://slsys.io/action/devicelists.html
3738
# Zigbee Model: [Manufacturer, Device Name, Device Model]
3839
# params: [lumi res name, xiaomi prop name, hass attr name, hass domain]
3940
DEVICES = [{
@@ -171,7 +172,7 @@
171172
'lumi.sensor_magnet': ["Xiaomi", "Door Sensor", "MCCGQ01LM"],
172173
'lumi.sensor_magnet.aq2': ["Aqara", "Door Sensor", "MCCGQ11LM"],
173174
'params': [
174-
['3.1.85', 'status', 'occupancy', 'binary_sensor'],
175+
['3.1.85', 'status', 'contact', 'binary_sensor'],
175176
]
176177
}, {
177178
# motion sensor

0 commit comments

Comments
 (0)