mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix motionEye switch refresh bug (#53413)
This commit is contained in:
parent
4b393f215d
commit
ffa7962a37
@ -20,7 +20,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from . import MotionEyeEntity, listen_for_new_cameras
|
from . import MotionEyeEntity, get_camera_from_cameras, listen_for_new_cameras
|
||||||
from .const import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_SWITCH_BASE
|
from .const import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_SWITCH_BASE
|
||||||
|
|
||||||
MOTIONEYE_SWITCHES = [
|
MOTIONEYE_SWITCHES = [
|
||||||
@ -118,3 +118,9 @@ class MotionEyeSwitch(MotionEyeEntity, SwitchEntity):
|
|||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
await self._async_send_set_camera(False)
|
await self._async_send_set_camera(False)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
"""Handle updated data from the coordinator."""
|
||||||
|
self._camera = get_camera_from_cameras(self._camera_id, self.coordinator.data)
|
||||||
|
super()._handle_coordinator_update()
|
||||||
|
@ -24,6 +24,7 @@ import homeassistant.util.dt as dt_util
|
|||||||
from . import (
|
from . import (
|
||||||
TEST_CAMERA,
|
TEST_CAMERA,
|
||||||
TEST_CAMERA_ID,
|
TEST_CAMERA_ID,
|
||||||
|
TEST_CAMERAS,
|
||||||
TEST_SWITCH_ENTITY_ID_BASE,
|
TEST_SWITCH_ENTITY_ID_BASE,
|
||||||
TEST_SWITCH_MOTION_DETECTION_ENTITY_ID,
|
TEST_SWITCH_MOTION_DETECTION_ENTITY_ID,
|
||||||
create_mock_motioneye_client,
|
create_mock_motioneye_client,
|
||||||
@ -38,7 +39,7 @@ async def test_switch_turn_on_off(hass: HomeAssistant) -> None:
|
|||||||
client = create_mock_motioneye_client()
|
client = create_mock_motioneye_client()
|
||||||
await setup_mock_motioneye_config_entry(hass, client=client)
|
await setup_mock_motioneye_config_entry(hass, client=client)
|
||||||
|
|
||||||
# Verify switch is on (as per TEST_COMPONENTS above).
|
# Verify switch is on.
|
||||||
entity_state = hass.states.get(TEST_SWITCH_MOTION_DETECTION_ENTITY_ID)
|
entity_state = hass.states.get(TEST_SWITCH_MOTION_DETECTION_ENTITY_ID)
|
||||||
assert entity_state
|
assert entity_state
|
||||||
assert entity_state.state == "on"
|
assert entity_state.state == "on"
|
||||||
@ -93,6 +94,29 @@ async def test_switch_turn_on_off(hass: HomeAssistant) -> None:
|
|||||||
assert entity_state.state == "on"
|
assert entity_state.state == "on"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_switch_state_update_from_coordinator(hass: HomeAssistant) -> None:
|
||||||
|
"""Test that coordinator data impacts state."""
|
||||||
|
client = create_mock_motioneye_client()
|
||||||
|
await setup_mock_motioneye_config_entry(hass, client=client)
|
||||||
|
|
||||||
|
# Verify switch is on.
|
||||||
|
entity_state = hass.states.get(TEST_SWITCH_MOTION_DETECTION_ENTITY_ID)
|
||||||
|
assert entity_state
|
||||||
|
assert entity_state.state == "on"
|
||||||
|
|
||||||
|
updated_cameras = copy.deepcopy(TEST_CAMERAS)
|
||||||
|
updated_cameras["cameras"][0][KEY_MOTION_DETECTION] = False
|
||||||
|
client.async_get_cameras = AsyncMock(return_value=updated_cameras)
|
||||||
|
|
||||||
|
async_fire_time_changed(hass, dt_util.utcnow() + DEFAULT_SCAN_INTERVAL)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Verify the switch turns off.
|
||||||
|
entity_state = hass.states.get(TEST_SWITCH_MOTION_DETECTION_ENTITY_ID)
|
||||||
|
assert entity_state
|
||||||
|
assert entity_state.state == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_has_correct_entities(hass: HomeAssistant) -> None:
|
async def test_switch_has_correct_entities(hass: HomeAssistant) -> None:
|
||||||
"""Test that the correct switch entities are created."""
|
"""Test that the correct switch entities are created."""
|
||||||
client = create_mock_motioneye_client()
|
client = create_mock_motioneye_client()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user