* Adding switch code for harmony activities * Working on-off * Removing poll code for now * Async updates for current activity * Update our state based on events * Notifications we got connected or disconnected * Remove unncessary constructor arg * Initial switch tests * Additional tests for switch transitions * Test transitions for availability * Testing switch state changes * Tests passing * Final tests * Updating manifest. * Correctly mock the return value from a call to the library * Adding new subscriber classes * Update class name and location * Got the refactor working locally. * Tests passing * Tracking state changes * Remove write_to_config_file - this appears to never be read. It was added far back in the past to account for a harmony library change, but nothing ever reads that path. Removing that side effect from tests is a pain - avoid the side effect completely. * Connection changes tested * Clean up temporary code * Update .coveragerc for harmony component Specifically exclude untested files instead of the whole module * Fix linting * test sending activity change commands by id * Improving coverage * Testing channel change commands * Splitting subscriber logic into it's own class * Improve coverage and tighten up .coveragerc * Test cleanups. * re-add config file writing for harmony remote * Create fixture for the mock harmonyclient * Reduce duplication in subscription callbacks * use async_run_job to call callbacks * Adding some tests for async behaviors with subscribers. * async_call_later for delay in marking remote unavailable * Test disconnection handling in harmony remote * Early exit if activity not specified * Use connection state mixin * Lint fix after rebase * Fix isort * super init for ConnectionStateMixin * Adding @mkeesey to harmony CODEOWNERS
67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
"""Test the Logitech Harmony Hub entities with connection state changes."""
|
|
|
|
from datetime import timedelta
|
|
|
|
from homeassistant.components.harmony.const import DOMAIN
|
|
from homeassistant.const import (
|
|
CONF_HOST,
|
|
CONF_NAME,
|
|
STATE_OFF,
|
|
STATE_ON,
|
|
STATE_UNAVAILABLE,
|
|
)
|
|
from homeassistant.util import utcnow
|
|
|
|
from .const import ENTITY_PLAY_MUSIC, ENTITY_REMOTE, ENTITY_WATCH_TV, HUB_NAME
|
|
|
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
|
|
|
|
|
async def test_connection_state_changes(mock_hc, hass, mock_write_config):
|
|
"""Ensure connection changes are reflected in the switch states."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN, data={CONF_HOST: "192.0.2.0", CONF_NAME: HUB_NAME}
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
data = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
# mocks start with current activity == Watch TV
|
|
assert hass.states.is_state(ENTITY_REMOTE, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_WATCH_TV, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_PLAY_MUSIC, STATE_OFF)
|
|
|
|
data._disconnected()
|
|
await hass.async_block_till_done()
|
|
|
|
# Entities do not immediately show as unavailable
|
|
assert hass.states.is_state(ENTITY_REMOTE, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_WATCH_TV, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_PLAY_MUSIC, STATE_OFF)
|
|
|
|
future_time = utcnow() + timedelta(seconds=10)
|
|
async_fire_time_changed(hass, future_time)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.is_state(ENTITY_REMOTE, STATE_UNAVAILABLE)
|
|
assert hass.states.is_state(ENTITY_WATCH_TV, STATE_UNAVAILABLE)
|
|
assert hass.states.is_state(ENTITY_PLAY_MUSIC, STATE_UNAVAILABLE)
|
|
|
|
data._connected()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.is_state(ENTITY_REMOTE, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_WATCH_TV, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_PLAY_MUSIC, STATE_OFF)
|
|
|
|
data._disconnected()
|
|
data._connected()
|
|
future_time = utcnow() + timedelta(seconds=10)
|
|
async_fire_time_changed(hass, future_time)
|
|
|
|
await hass.async_block_till_done()
|
|
assert hass.states.is_state(ENTITY_REMOTE, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_WATCH_TV, STATE_ON)
|
|
assert hass.states.is_state(ENTITY_PLAY_MUSIC, STATE_OFF)
|