Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix utility_meter calibration with float values #35186

Merged
merged 4 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/utility_meter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -222,7 +222,7 @@ async def async_reset_meter(self, entity_id):
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):
Expand Down
11 changes: 11 additions & 0 deletions tests/components/utility_meter/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down