Allow manually updating entity state in chacon dio (#124187)
* Addition of a reload service to manually retrieve the status of the devices. * Removal of reload_state service replaced by the homeassistant.update_entity supported service * remove api update to v1.2.1 for another PR * Review corrections * Review corrections
This commit is contained in:
parent
96edaebdd3
commit
16e52f0427
2 changed files with 44 additions and 2 deletions
|
@ -51,3 +51,11 @@ class ChaconDioEntity(Entity):
|
|||
_LOGGER.debug("Data received from server %s", data)
|
||||
self._update_attr(data)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update the state when the entity is requested to."""
|
||||
|
||||
_LOGGER.debug("Update called for %s, %s", self, self.target_id)
|
||||
data = await self.client.get_status_details([self.target_id])
|
||||
_LOGGER.debug("Received data from server %s", data)
|
||||
self._update_attr(data[self.target_id])
|
||||
|
|
|
@ -17,9 +17,11 @@ from homeassistant.components.cover import (
|
|||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
)
|
||||
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
|
@ -42,6 +44,38 @@ async def test_entities(
|
|||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
async def test_update(
|
||||
hass: HomeAssistant,
|
||||
mock_dio_chacon_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the creation and values of the Chacon Dio covers."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
mock_dio_chacon_client.get_status_details.return_value = {
|
||||
"L4HActuator_idmock1": {
|
||||
"id": "L4HActuator_idmock1",
|
||||
"connected": True,
|
||||
"openlevel": 51,
|
||||
"movement": "stop",
|
||||
}
|
||||
}
|
||||
|
||||
await async_setup_component(hass, HOMEASSISTANT_DOMAIN, {})
|
||||
await hass.services.async_call(
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
{ATTR_ENTITY_ID: COVER_ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get(COVER_ENTITY_ID)
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_CURRENT_POSITION) == 51
|
||||
assert state.state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_cover_actions(
|
||||
hass: HomeAssistant,
|
||||
mock_dio_chacon_client: AsyncMock,
|
||||
|
@ -100,7 +134,7 @@ async def test_cover_callbacks(
|
|||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the creation and values of the Chacon Dio covers."""
|
||||
"""Test the callbacks on the Chacon Dio covers."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue