mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Fix utility_meter calibration with float values (#35186)
This commit is contained in:
parent
96b84ff348
commit
53c1aba7df
@ -95,7 +95,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
|
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
SERVICE_CALIBRATE_METER,
|
SERVICE_CALIBRATE_METER,
|
||||||
{vol.Required(ATTR_VALUE): vol.Coerce(float)},
|
{vol.Required(ATTR_VALUE): vol.Coerce(Decimal)},
|
||||||
"async_calibrate",
|
"async_calibrate",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ class UtilityMeterSensor(RestoreEntity):
|
|||||||
async def async_calibrate(self, value):
|
async def async_calibrate(self, value):
|
||||||
"""Calibrate the Utility Meter with a given value."""
|
"""Calibrate the Utility Meter with a given value."""
|
||||||
_LOGGER.debug("Calibrate %s = %s", self._name, value)
|
_LOGGER.debug("Calibrate %s = %s", self._name, value)
|
||||||
self._state = Decimal(value)
|
self._state = value
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
|
@ -119,6 +119,17 @@ async def test_state(hass):
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "100"
|
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):
|
async def test_net_consumption(hass):
|
||||||
"""Test utility sensor state."""
|
"""Test utility sensor state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user