Add quarterly cycle for utility_meter component (#29534)
* Add quarterly tariff period to utility_meter Many tariff cycles in Australia are 3 monthly (quarterly). Add quarterly tariff cycle handling to the utility_meter component. * Add quarterly tariff period to utility_meter Many tariff cycles in Australia are 3 monthly (quarterly). Add quarterly tariff cycle handling to the utility_meter component. * Change date for test for utility_meter * Add quarterly tariff period to utility_meter Many tariff cycles in Australia are 3 monthly (quarterly). Add quarterly tariff cycle handling to the utility_meter component.pull/29607/head
parent
94b6cbc571
commit
de0db1601b
|
@ -5,9 +5,10 @@ HOURLY = "hourly"
|
|||
DAILY = "daily"
|
||||
WEEKLY = "weekly"
|
||||
MONTHLY = "monthly"
|
||||
QUARTERLY = "quarterly"
|
||||
YEARLY = "yearly"
|
||||
|
||||
METER_TYPES = [HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY]
|
||||
METER_TYPES = [HOURLY, DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY]
|
||||
|
||||
DATA_UTILITY = "utility_meter_data"
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ from .const import (
|
|||
DAILY,
|
||||
WEEKLY,
|
||||
MONTHLY,
|
||||
QUARTERLY,
|
||||
YEARLY,
|
||||
CONF_SOURCE_SENSOR,
|
||||
CONF_METER_TYPE,
|
||||
|
@ -184,6 +185,12 @@ class UtilityMeterSensor(RestoreEntity):
|
|||
and now != date(now.year, now.month, 1) + self._period_offset
|
||||
):
|
||||
return
|
||||
if (
|
||||
self._period == QUARTERLY
|
||||
and now
|
||||
!= date(now.year, (((now.month - 1) // 3) * 3 + 1), 1) + self._period_offset
|
||||
):
|
||||
return
|
||||
if self._period == YEARLY and now != date(now.year, 1, 1) + self._period_offset:
|
||||
return
|
||||
await self.async_reset_meter(self._tariff_entity)
|
||||
|
@ -209,7 +216,7 @@ class UtilityMeterSensor(RestoreEntity):
|
|||
minute=self._period_offset.seconds // 60,
|
||||
second=self._period_offset.seconds % 60,
|
||||
)
|
||||
elif self._period in [DAILY, WEEKLY, MONTHLY, YEARLY]:
|
||||
elif self._period in [DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY]:
|
||||
async_track_time_change(
|
||||
self.hass,
|
||||
self._async_reset_meter,
|
||||
|
|
|
@ -240,6 +240,13 @@ async def test_self_reset_monthly(hass):
|
|||
)
|
||||
|
||||
|
||||
async def test_self_reset_quarterly(hass):
|
||||
"""Test quarterly reset of meter."""
|
||||
await _test_self_reset(
|
||||
hass, gen_config("quarterly"), "2017-03-31T23:59:00.000000+00:00"
|
||||
)
|
||||
|
||||
|
||||
async def test_self_reset_yearly(hass):
|
||||
"""Test yearly reset of meter."""
|
||||
await _test_self_reset(
|
||||
|
|
Loading…
Reference in New Issue