mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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
@ -51,3 +51,11 @@ class ChaconDioEntity(Entity):
|
|||||||
_LOGGER.debug("Data received from server %s", data)
|
_LOGGER.debug("Data received from server %s", data)
|
||||||
self._update_attr(data)
|
self._update_attr(data)
|
||||||
self.async_write_ha_state()
|
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_OPEN,
|
||||||
STATE_OPENING,
|
STATE_OPENING,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
|
||||||
from homeassistant.const import ATTR_ENTITY_ID
|
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.helpers import entity_registry as er
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import setup_integration
|
from . import setup_integration
|
||||||
|
|
||||||
@ -42,6 +44,38 @@ async def test_entities(
|
|||||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
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(
|
async def test_cover_actions(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_dio_chacon_client: AsyncMock,
|
mock_dio_chacon_client: AsyncMock,
|
||||||
@ -100,7 +134,7 @@ async def test_cover_callbacks(
|
|||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> 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)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user