Update device registry of MQTT binary_sensor
This commit is contained in:
parent
1fcaaf93ad
commit
d8e43978b7
2 changed files with 55 additions and 5 deletions
|
@ -65,7 +65,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
try:
|
||||
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
|
||||
config = PLATFORM_SCHEMA(discovery_payload)
|
||||
await _async_setup_entity(config, async_add_entities,
|
||||
await _async_setup_entity(config, async_add_entities, config_entry,
|
||||
discovery_hash)
|
||||
except Exception:
|
||||
if discovery_hash:
|
||||
|
@ -77,16 +77,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
async_discover)
|
||||
|
||||
|
||||
async def _async_setup_entity(config, async_add_entities, discovery_hash=None):
|
||||
async def _async_setup_entity(config, async_add_entities, config_entry=None,
|
||||
discovery_hash=None):
|
||||
"""Set up the MQTT binary sensor."""
|
||||
async_add_entities([MqttBinarySensor(config, discovery_hash)])
|
||||
async_add_entities([MqttBinarySensor(config, config_entry,
|
||||
discovery_hash)])
|
||||
|
||||
|
||||
class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
||||
MqttEntityDeviceInfo, BinarySensorDevice):
|
||||
"""Representation a binary sensor that is updated by MQTT."""
|
||||
|
||||
def __init__(self, config, discovery_hash):
|
||||
def __init__(self, config, config_entry, discovery_hash):
|
||||
"""Initialize the MQTT binary sensor."""
|
||||
self._config = config
|
||||
self._unique_id = config.get(CONF_UNIQUE_ID)
|
||||
|
@ -100,7 +102,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||
MqttAvailability.__init__(self, config)
|
||||
MqttDiscoveryUpdate.__init__(self, discovery_hash,
|
||||
self.discovery_update)
|
||||
MqttEntityDeviceInfo.__init__(self, device_config)
|
||||
MqttEntityDeviceInfo.__init__(self, device_config, config_entry)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe mqtt events."""
|
||||
|
@ -113,6 +115,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||
self._config = config
|
||||
await self.attributes_discovery_update(config)
|
||||
await self.availability_discovery_update(config)
|
||||
await self.device_info_discovery_update(config)
|
||||
await self._subscribe_topics()
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue