diff --git a/custom_components/average/const.py b/custom_components/average/const.py index 19894ce..791cf0c 100644 --- a/custom_components/average/const.py +++ b/custom_components/average/const.py @@ -9,7 +9,7 @@ # Base component constants NAME = "Average Sensor" DOMAIN = "average" -VERSION = "1.7.2" +VERSION = "1.7.3.dev0" ISSUE_URL = "https://github.com/Limych/ha-average/issues" STARTUP_MESSAGE = f""" diff --git a/custom_components/average/manifest.json b/custom_components/average/manifest.json index 59acd4b..b9943f3 100644 --- a/custom_components/average/manifest.json +++ b/custom_components/average/manifest.json @@ -1,7 +1,7 @@ { "domain": "average", "name": "Average Sensor", - "version": "1.7.2", + "version": "1.7.3.dev0", "documentation": "https://github.com/Limych/ha-average", "issue_tracker": "https://github.com/Limych/ha-average/issues", "dependencies": [ diff --git a/custom_components/average/sensor.py b/custom_components/average/sensor.py index d4cc244..48da1db 100644 --- a/custom_components/average/sensor.py +++ b/custom_components/average/sensor.py @@ -202,7 +202,7 @@ def icon(self) -> Optional[str]: return self._icon @property - def device_state_attributes(self) -> Optional[Dict[str, Any]]: + def state_attributes(self) -> Optional[Dict[str, Any]]: """Return the state attributes.""" state_attr = { attr: getattr(self, attr) diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 0963a7a..e985c5e 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -19,7 +19,9 @@ ) from homeassistant.core import HomeAssistant from homeassistant.helpers.template import Template +from homeassistant.setup import async_setup_component from pytest import raises +from pytest_homeassistant_custom_component.common import assert_setup_component from voluptuous import Invalid from custom_components.average.const import CONF_DURATION, CONF_END, CONF_START, DOMAIN @@ -131,7 +133,7 @@ async def test_setup_platform(hass: HomeAssistant): assert async_add_entities.called -async def test_sensor_initialization(default_sensor): +async def test_entity_initialization(default_sensor): """Test sensor initialization.""" expected_attributes = { "available_sources": 0, @@ -147,22 +149,39 @@ async def test_sensor_initialization(default_sensor): assert default_sensor.state == STATE_UNAVAILABLE assert default_sensor.unit_of_measurement is None assert default_sensor.icon is None - assert default_sensor.device_state_attributes == expected_attributes - - -# -# -# async def test_async_added_to_hass(hass: HomeAssistant): -# """Test async added to hass.""" -# config = { -# CONF_PLATFORM: DOMAIN, -# CONF_NAME: "test", -# CONF_ENTITIES: ["sensor.test_monitored"], -# CONF_DURATION: timedelta(minutes=5), -# } -# -# await async_setup_component(hass, SENSOR, {SENSOR: config}) -# hass.block_till_done() + assert default_sensor.state_attributes == expected_attributes + + +async def test_async_setup_platform(hass: HomeAssistant): + """Test platform setup.""" + mock_sensor = { + "platform": "template", + "sensors": {"test_monitored": {"value_template": "{{ 2 }}"}}, + } + config = { + CONF_PLATFORM: DOMAIN, + CONF_ENTITIES: ["sensor.test_monitored", "sensor.nonexistent"], + } + + with assert_setup_component(2, "sensor"): + assert await async_setup_component( + hass, + "sensor", + { + "sensor": [ + config, + mock_sensor, + ] + }, + ) + await hass.async_block_till_done() + + await hass.async_start() + await hass.async_block_till_done() + + state = hass.states.get("sensor.average") + assert state is not None + assert state.state == "2.0" # pylint: disable=protected-access