Fix utility_meter calibration with float values (#35186)

pull/35225/head
Diogo Gomes 2020-05-05 01:44:00 +01:00 committed by GitHub
parent 96b84ff348
commit 53c1aba7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -95,7 +95,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
platform.async_register_entity_service(
SERVICE_CALIBRATE_METER,
{vol.Required(ATTR_VALUE): vol.Coerce(float)},
{vol.Required(ATTR_VALUE): vol.Coerce(Decimal)},
"async_calibrate",
)
@ -222,7 +222,7 @@ class UtilityMeterSensor(RestoreEntity):
async def async_calibrate(self, value):
"""Calibrate the Utility Meter with a given value."""
_LOGGER.debug("Calibrate %s = %s", self._name, value)
self._state = Decimal(value)
self._state = value
self.async_write_ha_state()
async def async_added_to_hass(self):

View File

@ -119,6 +119,17 @@ async def test_state(hass):
assert state is not None
assert state.state == "100"
await hass.services.async_call(
DOMAIN,
SERVICE_CALIBRATE_METER,
{ATTR_ENTITY_ID: "sensor.energy_bill_midpeak", ATTR_VALUE: "0.123"},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.energy_bill_midpeak")
assert state is not None
assert state.state == "0.123"
async def test_net_consumption(hass):
"""Test utility sensor state."""