Mqtt light refactor (#18227)

* Rename mqtt light files

* Refactor mqtt light

* Remove outdated testcase

* Add backwards compatibility for MQTT discovered MQTT lights.
Refactor according to review comments.
This commit is contained in:
emontnemery 2018-11-27 14:00:05 +01:00 committed by Paulus Schoutsen
parent c1ed2f17ac
commit 16e3ff2fec
9 changed files with 287 additions and 158 deletions

View file

@ -585,7 +585,8 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
'effect': 'random',
'color_temp': 100,
'white_value': 50})
with patch('homeassistant.components.light.mqtt.async_get_last_state',
with patch('homeassistant.components.light.mqtt.schema_basic'
'.async_get_last_state',
return_value=mock_coro(fake_state)):
with assert_setup_component(1, light.DOMAIN):
assert await async_setup_component(hass, light.DOMAIN, config)
@ -1063,3 +1064,20 @@ async def test_discovery_removal_light(hass, mqtt_mock, caplog):
state = hass.states.get('light.beer')
assert state is None
async def test_discovery_deprecated(hass, mqtt_mock, caplog):
"""Test removal of discovered mqtt_json lights."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {'mqtt': {}}, entry)
data = (
'{ "name": "Beer",'
' "platform": "mqtt",'
' "command_topic": "test_topic"}'
)
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
data)
await hass.async_block_till_done()
state = hass.states.get('light.beer')
assert state is not None
assert state.name == 'Beer'