Allows the utility_meter to net meter rather than only allow increases. (#21204)
* Allow the utility_meter to net meter rather than only allow increases. * Fix PR issues around CI. * Fix line length fallout. * Change rollover to net_consumption. Add unit tests. * Fix test style issues. * Fix style in tests.
This commit is contained in:
1 parent
616c7628d7
commit
02745be44d
4 files changed
+80
-9
No files matched your search
@@ -57,6 +57,72 @@ async def test_state(hass):
|
||||
assert state.state == '1'
|
||||
|
||||
|
||||
async def test_net_consumption(hass):
|
||||
"""Test utility sensor state."""
|
||||
config = {
|
||||
'utility_meter': {
|
||||
'energy_bill': {
|
||||
'source': 'sensor.energy',
|
||||
'net_consumption': True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
entity_id = config[DOMAIN]['energy_bill']['source']
|
||||
hass.states.async_set(entity_id, 2, {"unit_of_measurement": "kWh"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch('homeassistant.util.dt.utcnow',
|
||||
return_value=now):
|
||||
hass.states.async_set(entity_id, 1, {"unit_of_measurement": "kWh"},
|
||||
force_update=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('sensor.energy_bill')
|
||||
assert state is not None
|
||||
|
||||
assert state.state == '-1'
|
||||
|
||||
|
||||
async def test_non_net_consumption(hass):
|
||||
"""Test utility sensor state."""
|
||||
config = {
|
||||
'utility_meter': {
|
||||
'energy_bill': {
|
||||
'source': 'sensor.energy',
|
||||
'net_consumption': False
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
entity_id = config[DOMAIN]['energy_bill']['source']
|
||||
hass.states.async_set(entity_id, 2, {"unit_of_measurement": "kWh"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch('homeassistant.util.dt.utcnow',
|
||||
return_value=now):
|
||||
hass.states.async_set(entity_id, 1, {"unit_of_measurement": "kWh"},
|
||||
force_update=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('sensor.energy_bill')
|
||||
assert state is not None
|
||||
|
||||
assert state.state == '0'
|
||||
|
||||
|
||||
async def _test_self_reset(hass, cycle, start_time, expect_reset=True):
|
||||
"""Test energy sensor self reset."""
|
||||
config = {
|
||||
|
||||
Reference in new issue
Block a user