Add binary sensor for myq gateway connectivity (#33423)
This commit is contained in:
1 parent
12b408219e
commit
b783aab41b
8 files changed
+397
-3
No files matched your search
@@ -0,0 +1,108 @@
|
||||
"""Support for MyQ gateways."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
BinarySensorDevice,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
KNOWN_MODELS,
|
||||
MANUFACTURER,
|
||||
MYQ_COORDINATOR,
|
||||
MYQ_DEVICE_FAMILY,
|
||||
MYQ_DEVICE_FAMILY_GATEWAY,
|
||||
MYQ_DEVICE_STATE,
|
||||
MYQ_DEVICE_STATE_ONLINE,
|
||||
MYQ_GATEWAY,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up mysq covers."""
|
||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
myq = data[MYQ_GATEWAY]
|
||||
coordinator = data[MYQ_COORDINATOR]
|
||||
|
||||
entities = []
|
||||
|
||||
for device in myq.devices.values():
|
||||
if device.device_json[MYQ_DEVICE_FAMILY] == MYQ_DEVICE_FAMILY_GATEWAY:
|
||||
entities.append(MyQBinarySensorDevice(coordinator, device))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class MyQBinarySensorDevice(BinarySensorDevice):
|
||||
"""Representation of a MyQ gateway."""
|
||||
|
||||
def __init__(self, coordinator, device):
|
||||
"""Initialize with API object, device id."""
|
||||
self._coordinator = coordinator
|
||||
self._device = device
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""We track connectivity for gateways."""
|
||||
return DEVICE_CLASS_CONNECTIVITY
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the garage door if any."""
|
||||
return f"{self._device.name} MyQ Gateway"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return if the device is online."""
|
||||
if not self._coordinator.last_update_success:
|
||||
return False
|
||||
|
||||
# Not all devices report online so assume True if its missing
|
||||
return self._device.device_json[MYQ_DEVICE_STATE].get(
|
||||
MYQ_DEVICE_STATE_ONLINE, True
|
||||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return self._device.device_id
|
||||
|
||||
async def async_update(self):
|
||||
"""Update status of cover."""
|
||||
await self._coordinator.async_request_refresh()
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
device_info = {
|
||||
"identifiers": {(DOMAIN, self._device.device_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"sw_version": self._device.firmware_version,
|
||||
}
|
||||
model = KNOWN_MODELS.get(self._device.device_id[2:4])
|
||||
if model:
|
||||
device_info["model"] = model
|
||||
|
||||
return device_info
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return False, updates are controlled via coordinator."""
|
||||
return False
|
||||
|
||||
@callback
|
||||
def _async_consume_update(self):
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._coordinator.async_add_listener(self._async_consume_update)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
self._coordinator.async_remove_listener(self._async_consume_update)
|
||||
@@ -10,10 +10,14 @@ from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_O
|
||||
|
||||
DOMAIN = "myq"
|
||||
|
||||
PLATFORMS = ["cover"]
|
||||
PLATFORMS = ["cover", "binary_sensor"]
|
||||
|
||||
MYQ_DEVICE_TYPE = "device_type"
|
||||
MYQ_DEVICE_TYPE_GATE = "gate"
|
||||
|
||||
MYQ_DEVICE_FAMILY = "device_family"
|
||||
MYQ_DEVICE_FAMILY_GATEWAY = "gateway"
|
||||
|
||||
MYQ_DEVICE_STATE = "state"
|
||||
MYQ_DEVICE_STATE_ONLINE = "online"
|
||||
|
||||
@@ -39,3 +43,36 @@ TRANSITION_START_DURATION = 7
|
||||
# Estimated time it takes myq to complete a transition
|
||||
# from one state to another
|
||||
TRANSITION_COMPLETE_DURATION = 37
|
||||
|
||||
MANUFACTURER = "The Chamberlain Group Inc."
|
||||
|
||||
KNOWN_MODELS = {
|
||||
"00": "Chamberlain Ethernet Gateway",
|
||||
"01": "LiftMaster Ethernet Gateway",
|
||||
"02": "Craftsman Ethernet Gateway",
|
||||
"03": "Chamberlain Wi-Fi hub",
|
||||
"04": "LiftMaster Wi-Fi hub",
|
||||
"05": "Craftsman Wi-Fi hub",
|
||||
"08": "LiftMaster Wi-Fi GDO DC w/Battery Backup",
|
||||
"09": "Chamberlain Wi-Fi GDO DC w/Battery Backup",
|
||||
"10": "Craftsman Wi-Fi GDO DC 3/4HP",
|
||||
"11": "MyQ Replacement Logic Board Wi-Fi GDO DC 3/4HP",
|
||||
"12": "Chamberlain Wi-Fi GDO DC 1.25HP",
|
||||
"13": "LiftMaster Wi-Fi GDO DC 1.25HP",
|
||||
"14": "Craftsman Wi-Fi GDO DC 1.25HP",
|
||||
"15": "MyQ Replacement Logic Board Wi-Fi GDO DC 1.25HP",
|
||||
"0A": "Chamberlain Wi-Fi GDO or Gate Operator AC",
|
||||
"0B": "LiftMaster Wi-Fi GDO or Gate Operator AC",
|
||||
"0C": "Craftsman Wi-Fi GDO or Gate Operator AC",
|
||||
"0D": "MyQ Replacement Logic Board Wi-Fi GDO or Gate Operator AC",
|
||||
"0E": "Chamberlain Wi-Fi GDO DC 3/4HP",
|
||||
"0F": "LiftMaster Wi-Fi GDO DC 3/4HP",
|
||||
"20": "Chamberlain MyQ Home Bridge",
|
||||
"21": "LiftMaster MyQ Home Bridge",
|
||||
"23": "Chamberlain Smart Garage Hub",
|
||||
"24": "LiftMaster Smart Garage Hub",
|
||||
"27": "LiftMaster Wi-Fi Wall Mount opener",
|
||||
"28": "LiftMaster Commercial Wi-Fi Wall Mount operator",
|
||||
"80": "EU LiftMaster Ethernet Gateway",
|
||||
"81": "EU Chamberlain Ethernet Gateway",
|
||||
}
|
||||
@@ -27,6 +27,8 @@ from homeassistant.helpers.event import async_call_later
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
KNOWN_MODELS,
|
||||
MANUFACTURER,
|
||||
MYQ_COORDINATOR,
|
||||
MYQ_DEVICE_STATE,
|
||||
MYQ_DEVICE_STATE_ONLINE,
|
||||
@@ -181,9 +183,12 @@ class MyQDevice(CoverDevice):
|
||||
device_info = {
|
||||
"identifiers": {(DOMAIN, self._device.device_id)},
|
||||
"name": self._device.name,
|
||||
"manufacturer": "The Chamberlain Group Inc.",
|
||||
"manufacturer": MANUFACTURER,
|
||||
"sw_version": self._device.firmware_version,
|
||||
}
|
||||
model = KNOWN_MODELS.get(self._device.device_id[2:4])
|
||||
if model:
|
||||
device_info["model"] = model
|
||||
if self._device.parent_device_id:
|
||||
device_info["via_device"] = (DOMAIN, self._device.parent_device_id)
|
||||
return device_info
|
||||
|
||||
Reference in new issue
Block a user