Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version = 1

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"

[[transformers]]
name = "black"
enabled = true

[[transformers]]
name = "isort"
enabled = true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A sensor will be created for each meter showing:
For electric meters the readings are in kWh. For gas meter the readings are in m³.

An additional sensor is created for gas meters showing the latest reading in kWh.
The integration refreshes the data only every 12 hours (as eon only updates the data every two weeks!)


## Installation
Expand All @@ -22,4 +23,4 @@ Setting up this component is done entirely in the UI. Go to your Integration set

The setup wizard will ask you to enter your account login details, and that is all there is too it!

The integration should now be showing on your list, along with a number of new entities for all the sensors it has created.
The integration should now be showing on your list, along with a number of new entities for all the sensors it has created.
18 changes: 14 additions & 4 deletions custom_components/eon_next/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import logging
from .eonnext import EonNext
from homeassistant.const import Platform

_LOGGER = logging.getLogger(__name__)

DOMAIN = "eon_next"
CONF_EMAIL = "email"
CONF_PASSWORD = "password"

PLATFORMS: list[Platform] = [Platform.SENSOR]

async def async_setup_entry(hass, entry):
"""Set up platform from a ConfigEntry."""
Expand All @@ -21,11 +23,19 @@ async def async_setup_entry(hass, entry):

hass.data[DOMAIN][entry.entry_id] = api

hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
#hass.async_create_task(
# hass.config_entries.async_forward_entry_setup(entry, "sensor")
#)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True

else:
return False
return False

async def async_unload_entry(hass, entry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
2 changes: 1 addition & 1 deletion custom_components/eon_next/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/madmachinations/eon-next/issues",
"requirements": [],
"version": "0.1.0"
"version": "0.2.0"
}
10 changes: 8 additions & 2 deletions custom_components/eon_next/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import logging

from datetime import timedelta

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity
Expand All @@ -16,6 +18,8 @@
from .eonnext import METER_TYPE_GAS, METER_TYPE_ELECTRIC

_LOGGER = logging.getLogger(__name__)
# Eon updates the reading only every two weeks ! - so set this to be much mroe than every minute, which is HA default.
SCAN_INTERVAL = timedelta(hours=12)


async def async_setup_entry(hass, config_entry, async_add_entities):
Expand Down Expand Up @@ -51,6 +55,7 @@ def __init__(self, meter):
self._attr_device_class = SensorDeviceClass.DATE
self._attr_icon = "mdi:calendar"
self._attr_unique_id = self.meter.get_serial() + "__" + "reading_date"
self.update_interval = SCAN_INTERVAL


async def async_update(self) -> None:
Expand All @@ -70,6 +75,7 @@ def __init__(self, meter):
self._attr_state_class = "total"
self._attr_icon = "mdi:meter-electric-outline"
self._attr_unique_id = self.meter.get_serial() + "__" + "electricity_kwh"
self.update_interval = SCAN_INTERVAL


async def async_update(self) -> None:
Expand All @@ -89,7 +95,7 @@ def __init__(self, meter):
self._attr_state_class = "total"
self._attr_icon = "mdi:meter-gas-outline"
self._attr_unique_id = self.meter.get_serial() + "__" + "gas_kwh"

self.update_interval = SCAN_INTERVAL

async def async_update(self) -> None:
self._attr_native_value = await self.meter.get_latest_reading_kwh()
Expand All @@ -108,7 +114,7 @@ def __init__(self, meter):
self._attr_state_class = "total"
self._attr_icon = "mdi:meter-gas-outline"
self._attr_unique_id = self.meter.get_serial() + "__" + "gas_m3"

self.update_interval = SCAN_INTERVAL

async def async_update(self) -> None:
self._attr_native_value = await self.meter.get_latest_reading()
Expand Down