mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix reconfiguring of Tasmota lights (#42288)
This commit is contained in:
parent
15f46392d2
commit
bfb603fe78
@ -80,10 +80,11 @@ class TasmotaLight(
|
||||
|
||||
self._setup_from_entity()
|
||||
|
||||
async def discovery_update(self, update):
|
||||
async def discovery_update(self, update, write_state=True):
|
||||
"""Handle updated discovery message."""
|
||||
await super().discovery_update(update, write_state=False)
|
||||
self._setup_from_entity()
|
||||
await super().discovery_update(update)
|
||||
self.async_write_ha_state()
|
||||
|
||||
def _setup_from_entity(self):
|
||||
"""(Re)Setup the entity."""
|
||||
|
@ -38,11 +38,12 @@ class TasmotaEntity(Entity):
|
||||
await self._tasmota_entity.unsubscribe_topics()
|
||||
await super().async_will_remove_from_hass()
|
||||
|
||||
async def discovery_update(self, update):
|
||||
async def discovery_update(self, update, write_state=True):
|
||||
"""Handle updated discovery message."""
|
||||
self._tasmota_entity.config_update(update)
|
||||
await self._subscribe_topics()
|
||||
self.async_write_ha_state()
|
||||
if write_state:
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def _subscribe_topics(self):
|
||||
"""(Re)Subscribe to topics."""
|
||||
|
@ -385,7 +385,7 @@ async def help_test_discovery_update_unchanged(
|
||||
entity_id="test",
|
||||
name="Test",
|
||||
):
|
||||
"""Test update of discovered component without changes.
|
||||
"""Test update of discovered component with and without changes.
|
||||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
|
@ -2,6 +2,8 @@
|
||||
import copy
|
||||
import json
|
||||
|
||||
from hatasmota.const import CONF_MAC
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.components.light import (
|
||||
SUPPORT_BRIGHTNESS,
|
||||
@ -771,6 +773,38 @@ async def test_unlinked_light2(hass, mqtt_mock, setup_tasmota):
|
||||
await _test_unlinked_light(hass, mqtt_mock, config, 2)
|
||||
|
||||
|
||||
async def test_discovery_update_reconfigure_light(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
"""Test reconfigure of discovered light."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
config["lt_st"] = 1 # 1 channel light (Dimmer)
|
||||
config2 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config2["rl"][0] = 2
|
||||
config2["lt_st"] = 3 # 3 channel light (RGB)
|
||||
data1 = json.dumps(config)
|
||||
data2 = json.dumps(config2)
|
||||
|
||||
# Simple dimmer
|
||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config", data1)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.test")
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
||||
)
|
||||
|
||||
# Reconfigure as RGB light
|
||||
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{config[CONF_MAC]}/config", data2)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("light.test")
|
||||
assert (
|
||||
state.attributes.get("supported_features")
|
||||
== SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT | SUPPORT_TRANSITION
|
||||
)
|
||||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
|
Loading…
x
Reference in New Issue
Block a user