Files
core/tests/components/steamist/test_sensor.py
Abílio Costa b626204f63 Add default device class display precision for Sensor (#145013)
* Add default device class display precision for Sensor

* Renaming, docstrings, cleanup

* Simplify units list

* Fix tests

* Fix missing precision when suggested is specified

* Update snapshots

* Fix when unit of measurement is not valid

* Fix tests

* Fix deprecated unit usage

* Fix goalzero tests

The sensor native_value method was accessing the data dict and trowing,
since the mock did not have any data for the sensors.

Since now the precision is always specified (it was missing for those
sensors), the throw was hitting async_update_entity_options in _update_suggested_precision.
Previously, async_update_entity_options was not called since it had no
precision.

* Fix metoffice

* Fix smartthings

* Add default sensor data for Tesla Wall Connector tests

* Update snapshots

* Revert spaces

* Update smartthings snapshots

* Add missing sensor mock for tesla wall connector

* Address review comments

* Add doc comment

* Add cap to doc comment

* Update comment

* Update snapshots

* Update comment
2025-05-26 19:40:29 +02:00

35 lines
1.5 KiB
Python

"""Tests for the steamist sensos."""
from __future__ import annotations
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime
from homeassistant.core import HomeAssistant
from . import (
MOCK_ASYNC_GET_STATUS_ACTIVE,
MOCK_ASYNC_GET_STATUS_INACTIVE,
_async_setup_entry_with_status,
)
async def test_steam_active(hass: HomeAssistant) -> None:
"""Test that the sensors are setup with the expected values when steam is active."""
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
state = hass.states.get("sensor.steam_temperature")
assert round(float(state.state)) == 39
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
state = hass.states.get("sensor.steam_minutes_remain")
assert state.state == "14"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
async def test_steam_inactive(hass: HomeAssistant) -> None:
"""Test that the sensors are setup with the expected values when steam is not active."""
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE)
state = hass.states.get("sensor.steam_temperature")
assert round(float(state.state)) == 21
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
state = hass.states.get("sensor.steam_minutes_remain")
assert state.state == "0"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES