Skip to content

Commit

Permalink
Fix door sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 1, 2020
1 parent e5503df commit 27df906
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion custom_components/xiaomi_gateway3/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

_LOGGER = logging.getLogger(__name__)

DEVICE_CLASS = {
'contact': 'door'
}


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

@property
def device_class(self):
return self._attr
return DEVICE_CLASS.get(self._attr, self._attr)

def update(self, data: dict = None):
if self._attr not in data:
Expand Down
8 changes: 4 additions & 4 deletions custom_components/xiaomi_gateway3/gateway3.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def _get_devices1(self) -> Optional[list]:
for k, v in data.items():
if k in ('temperature', 'humidity'):
data[k] = v / 100.0
elif v == 'on':
elif v in ('on', 'open'):
data[k] = 1
elif v == 'off':
elif v in ('off', 'close'):
data[k] = 0

device['init'] = data
Expand Down Expand Up @@ -225,8 +225,8 @@ def _enable_mqtt(self):

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

def on_disconnect(self, client, userdata, rc):
_LOGGER.debug(f"{self.host} | MQTT disconnected")
Expand Down
3 changes: 2 additions & 1 deletion custom_components/xiaomi_gateway3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}

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

0 comments on commit 27df906

Please sign in to comment.