Skip to content

Commit

Permalink
Add monthly report (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tetienne authored Dec 12, 2020
1 parent bbac1c7 commit 9d5ca1b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
4 changes: 1 addition & 3 deletions custom_components/veolia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
COORDINATOR,
DOMAIN,
PLATFORMS,
STARTUP_MESSAGE,
)

SCAN_INTERVAL = timedelta(days=1)
Expand All @@ -41,7 +40,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up this integration using UI."""
if hass.data.get(DOMAIN) is None:
hass.data.setdefault(DOMAIN, {})
_LOGGER.info(STARTUP_MESSAGE)

username = entry.data.get(CONF_USERNAME)
password = entry.data.get(CONF_PASSWORD)
Expand All @@ -59,7 +57,7 @@ async def _get_consumption():
coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name="somfy device update",
name="veolia consumption update",
update_method=_get_consumption,
update_interval=SCAN_INTERVAL,
)
Expand Down
24 changes: 0 additions & 24 deletions custom_components/veolia/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,10 @@

from homeassistant.components.sensor import DOMAIN as SENSOR

# Base component constants
NAME = "Veolia"
DOMAIN = "veolia"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "0.1.0"

ISSUE_URL = "https://github.com/tetienne/veolia-custom-component/issues"

# Platforms
PLATFORMS = [SENSOR]


# Configuration and options
CONF_USERNAME = "username"
CONF_PASSWORD = "password"

# Defaults
DEFAULT_NAME = DOMAIN
API = "api"
COORDINATOR = "coordinator"


STARTUP_MESSAGE = f"""
-------------------------------------------------------------------
{NAME}
Version: {VERSION}
This is a custom integration!
If you have any issues with this you need to open an issue here:
{ISSUE_URL}
-------------------------------------------------------------------
"""
1 change: 1 addition & 0 deletions custom_components/veolia/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def device_info(self):
return {
"identifiers": {(self.config_entry.entry_id, DOMAIN)},
"manufacturer": NAME,
"name": NAME,
}

@property
Expand Down
31 changes: 30 additions & 1 deletion custom_components/veolia/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
coordinator = hass.data[DOMAIN][COORDINATOR]
async_add_devices([VeoliaDailyUsageSensor(coordinator, entry)])
async_add_devices(
[
VeoliaDailyUsageSensor(coordinator, entry),
VeoliaMonthlyUsageSensor(coordinator, entry),
]
)


class VeoliaDailyUsageSensor(VeoliaEntity):
Expand All @@ -33,3 +38,27 @@ def icon(self) -> str:
def unit_of_measurement(self) -> str:
"""Return liter as the unit measurement for water."""
return VOLUME_LITERS


class VeoliaMonthlyUsageSensor(VeoliaEntity):
"""Monitors the daily water usage."""

@property
def name(self):
"""Return the name of the sensor."""
return "veolia_monthly_consumption"

@property
def state(self):
"""Return the state of the sensor."""
return sum(self.coordinator.data.values())

@property
def icon(self) -> str:
"""Return the daily usage icon."""
return "mdi:water"

@property
def unit_of_measurement(self) -> str:
"""Return liter as the unit measurement for water."""
return VOLUME_LITERS

0 comments on commit 9d5ca1b

Please sign in to comment.