Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entities after a set_meter_reading service is called #2

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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