Add MQTT WS command to remove device (#31989)
* Add MQTT WS command to remove device * Review comments, fix test * Fix tests
This commit is contained in:
parent
4236d62b44
commit
7e387f93d6
26 changed files with 473 additions and 124 deletions
|
@ -243,15 +243,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
async def async_discover(discovery_payload):
|
||||
"""Discover and add a MQTT climate device."""
|
||||
discovery_data = discovery_payload.discovery_data
|
||||
try:
|
||||
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
|
||||
config = PLATFORM_SCHEMA(discovery_payload)
|
||||
await _async_setup_entity(
|
||||
hass, config, async_add_entities, config_entry, discovery_hash
|
||||
hass, config, async_add_entities, config_entry, discovery_data
|
||||
)
|
||||
except Exception:
|
||||
if discovery_hash:
|
||||
clear_discovery_hash(hass, discovery_hash)
|
||||
clear_discovery_hash(hass, discovery_data[ATTR_DISCOVERY_HASH])
|
||||
raise
|
||||
|
||||
async_dispatcher_connect(
|
||||
|
@ -260,10 +259,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
|
||||
async def _async_setup_entity(
|
||||
hass, config, async_add_entities, config_entry=None, discovery_hash=None
|
||||
hass, config, async_add_entities, config_entry=None, discovery_data=None
|
||||
):
|
||||
"""Set up the MQTT climate devices."""
|
||||
async_add_entities([MqttClimate(hass, config, config_entry, discovery_hash)])
|
||||
async_add_entities([MqttClimate(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttClimate(
|
||||
|
@ -275,7 +274,7 @@ class MqttClimate(
|
|||
):
|
||||
"""Representation of an MQTT climate device."""
|
||||
|
||||
def __init__(self, hass, config, config_entry, discovery_hash):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the climate device."""
|
||||
self._config = config
|
||||
self._unique_id = config.get(CONF_UNIQUE_ID)
|
||||
|
@ -303,7 +302,7 @@ class MqttClimate(
|
|||
|
||||
MqttAttributes.__init__(self, config)
|
||||
MqttAvailability.__init__(self, config)
|
||||
MqttDiscoveryUpdate.__init__(self, discovery_hash, self.discovery_update)
|
||||
MqttDiscoveryUpdate.__init__(self, discovery_data, self.discovery_update)
|
||||
MqttEntityDeviceInfo.__init__(self, device_config, config_entry)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
|
@ -552,6 +551,7 @@ class MqttClimate(
|
|||
)
|
||||
await MqttAttributes.async_will_remove_from_hass(self)
|
||||
await MqttAvailability.async_will_remove_from_hass(self)
|
||||
await MqttDiscoveryUpdate.async_will_remove_from_hass(self)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue