Add support for enabling/disabling cloud access in flux_led (#61138)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2021-12-19 00:59:16 -06:00 committed by GitHub
parent d7c5e41802
commit a6b680cd32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 428 additions and 111 deletions

View file

@ -1,6 +1,6 @@
"""Tests for switch platform."""
from homeassistant.components import flux_led
from homeassistant.components.flux_led.const import DOMAIN
from homeassistant.components.flux_led.const import CONF_REMOTE_ACCESS_ENABLED, DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -16,6 +16,7 @@ from . import (
DEFAULT_ENTRY_TITLE,
IP_ADDRESS,
MAC_ADDRESS,
_mocked_bulb,
_mocked_switch,
_patch_discovery,
_patch_wifibulb,
@ -27,7 +28,7 @@ from tests.common import MockConfigEntry
async def test_switch_on_off(hass: HomeAssistant) -> None:
"""Test a switch light."""
"""Test a smart plug."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
@ -60,3 +61,37 @@ async def test_switch_on_off(hass: HomeAssistant) -> None:
await async_mock_device_turn_on(hass, switch)
assert hass.states.get(entity_id).state == STATE_ON
async def test_remote_access_on_off(hass: HomeAssistant) -> None:
"""Test enable/disable remote access."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
unique_id=MAC_ADDRESS,
)
config_entry.add_to_hass(hass)
bulb = _mocked_bulb()
with _patch_discovery(), _patch_wifibulb(bulb):
await async_setup_component(hass, flux_led.DOMAIN, {flux_led.DOMAIN: {}})
await hass.async_block_till_done()
entity_id = "switch.bulb_rgbcw_ddeeff_remote_access"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
await hass.services.async_call(
SWITCH_DOMAIN, "turn_off", {ATTR_ENTITY_ID: entity_id}, blocking=True
)
bulb.async_disable_remote_access.assert_called_once()
assert hass.states.get(entity_id).state == STATE_OFF
assert config_entry.data[CONF_REMOTE_ACCESS_ENABLED] is False
await hass.services.async_call(
SWITCH_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
)
bulb.async_enable_remote_access.assert_called_once()
assert hass.states.get(entity_id).state == STATE_ON
assert config_entry.data[CONF_REMOTE_ACCESS_ENABLED] is True