Skip to content

Commit

Permalink
Merge pull request #2 from tijsverkoyen/refresh-reading-after-service…
Browse files Browse the repository at this point in the history
…-call

Update entities after a set_meter_reading service is called
  • Loading branch information
tijsverkoyen authored Nov 3, 2022
2 parents e3e3259 + 0ffb94a commit fe1e59a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom_components/energy_id/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from homeassistant.core import callback, HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.entity_registry import async_entries_for_device
from homeassistant.exceptions import HomeAssistantError

from .const import DOMAIN, CONF_RECORD, CONF_METER_IDS, CONF_ENERGY_ID_API_HOST, CONF_API_KEY
Expand Down Expand Up @@ -67,6 +68,10 @@ async def handle_set_meter_reading(call: ServiceCall):
except EnergyIDApiError as e:
raise HomeAssistantError(f'Invalid response from EnergyID API: {e}')

entity_registry = er.async_get(hass)
entities = async_entries_for_device(entity_registry, device.id)
await hass.services.async_call('homeassistant', 'update_entity', {'entity_id': entities[0].entity_id})

hass.services.async_register(
DOMAIN,
'set_meter_reading',
Expand Down

0 comments on commit fe1e59a

Please sign in to comment.