diff --git a/custom_components/ac_infinity/config_flow.py b/custom_components/ac_infinity/config_flow.py index 446b28e..05dac51 100644 --- a/custom_components/ac_infinity/config_flow.py +++ b/custom_components/ac_infinity/config_flow.py @@ -141,6 +141,7 @@ async def async_step_init( cur_value = ( int(self.config_entry.data[CONF_POLLING_INTERVAL]) if CONF_POLLING_INTERVAL in self.config_entry.data + and self.config_entry.data[CONF_POLLING_INTERVAL] is not None else DEFAULT_POLLING_INTERVAL ) diff --git a/custom_components/ac_infinity/manifest.json b/custom_components/ac_infinity/manifest.json index e0a30af..db80d33 100644 --- a/custom_components/ac_infinity/manifest.json +++ b/custom_components/ac_infinity/manifest.json @@ -10,5 +10,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/dalinicus/homeassistant-acinfinity", "requirements": [], - "version": "1.4.2" + "version": "1.4.3" } diff --git a/custom_components/ac_infinity/sensor.py b/custom_components/ac_infinity/sensor.py index 42eaf31..a9e1c43 100644 --- a/custom_components/ac_infinity/sensor.py +++ b/custom_components/ac_infinity/sensor.py @@ -7,6 +7,7 @@ SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -62,6 +63,7 @@ class ACInfinityPortSensorEntityDescription( ACInfinityControllerSensorEntityDescription( key=SENSOR_KEY_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfTemperature.CELSIUS, icon=None, # default translation_key="temperature", @@ -76,6 +78,7 @@ class ACInfinityPortSensorEntityDescription( ACInfinityControllerSensorEntityDescription( key=SENSOR_KEY_HUMIDITY, device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, icon=None, # default translation_key="humidity", @@ -88,6 +91,7 @@ class ACInfinityPortSensorEntityDescription( ACInfinityControllerSensorEntityDescription( key=SENSOR_KEY_VPD, device_class=SensorDeviceClass.PRESSURE, + state_class=SensorStateClass.MEASUREMENT, suggested_unit_of_measurement=UnitOfPressure.KPA, native_unit_of_measurement=UnitOfPressure.KPA, icon="mdi:water-thermometer", @@ -104,6 +108,7 @@ class ACInfinityPortSensorEntityDescription( ACInfinityPortSensorEntityDescription( key=SENSOR_PORT_KEY_SPEAK, device_class=SensorDeviceClass.POWER_FACTOR, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=None, # no units / bare integer value icon=None, # default translation_key="current_power", diff --git a/tests/__init__.py b/tests/__init__.py index 24d6e89..d0bbf2a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -54,7 +54,7 @@ async def execute_and_get_controller_entity( await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) @@ -78,7 +78,7 @@ async def execute_and_get_port_entity( await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) @@ -96,7 +96,6 @@ def setup_entity_mocks(mocker: MockFixture): future: Future = asyncio.Future() future.set_result(None) - mocker.patch.object(ConfigEntry, "__init__", return_value=None) mocker.patch.object(HomeAssistant, "__init__", return_value=None) write_ha_mock = mocker.patch.object( Entity, "async_write_ha_state", return_value=None @@ -120,9 +119,15 @@ def setup_entity_mocks(mocker: MockFixture): hass.data = {DOMAIN: {ENTRY_ID: coordinator}} - config_entry = ConfigEntry() - config_entry.entry_id = ENTRY_ID - config_entry.data = {CONF_EMAIL: ENTRY_ID} + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={CONF_EMAIL: ENTRY_ID}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, + ) entities = EntitiesTracker() @@ -156,7 +161,7 @@ class ACTestObjects: def __init__( self, hass, - configEntry, + config_entry, entities, ac_infinity, set_mock, @@ -167,7 +172,7 @@ def __init__( options_flow, ) -> None: self.hass: HomeAssistant = hass - self.configEntry: ConfigEntry = configEntry + self.config_entry: ConfigEntry = config_entry self.entities: EntitiesTracker = entities self.ac_infinity: ACInfinity = ac_infinity self.set_mock: MockType = set_mock diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 2f4c3c4..491c677 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -34,7 +34,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index d072559..dcfc1a0 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -6,6 +6,7 @@ import pytest import voluptuous as vol from homeassistant import config_entries +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from pytest_mock import MockFixture @@ -24,10 +25,11 @@ CONF_POLLING_INTERVAL, CONF_UPDATE_PASSWORD, DEFAULT_POLLING_INTERVAL, + DOMAIN, ) from tests import ACTestObjects, setup_entity_mocks -from .data_models import EMAIL, PASSWORD, POLLING_INTERVAL +from .data_models import EMAIL, ENTRY_ID, PASSWORD, POLLING_INTERVAL CONFIG_FLOW_USER_INPUT = {CONF_EMAIL: EMAIL, CONF_PASSWORD: PASSWORD} OPTION_FLOW_USER_INPUT = {CONF_POLLING_INTERVAL: POLLING_INTERVAL} @@ -141,8 +143,14 @@ async def test_async_get_options_flow_returns_options_flow( self, mocker: MockFixture ): """options flow returned from static method""" - config_entry = mocker.patch.object( - config_entries.ConfigEntry, "data", return_value={} + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, ) result = ConfigFlow.async_get_options_flow(config_entry) @@ -157,11 +165,16 @@ async def test_options_flow_handler_show_form( ): """If no user input provided, async_setup_init should show form with correct value""" - config_entry = mocker.patch.object( - config_entries.ConfigEntry, - "data", - return_value={CONF_POLLING_INTERVAL: existing_value}, + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={CONF_POLLING_INTERVAL: existing_value}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, ) + flow = OptionsFlow(config_entry) await flow.async_step_init() @@ -181,10 +194,16 @@ async def test_options_flow_handler_show_form_uninitalized( self, mocker: MockFixture, setup_options_flow ): """If no user input provided, and no interval exists in settings, async_setup_init should show form with default value""" - - config_entry = mocker.patch.object( - config_entries.ConfigEntry, "data", return_value={} + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, ) + flow = OptionsFlow(config_entry) await flow.async_step_init() @@ -208,8 +227,14 @@ async def test_options_flow_handler_show_form_with_error_polling_interval( ): """If provided polling interval is not valid, show form with error""" - config_entry = mocker.patch.object( - config_entries.ConfigEntry, "data", return_value={} + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, ) flow = OptionsFlow(config_entry) await flow.async_step_init({CONF_POLLING_INTERVAL: user_input}) diff --git a/tests/test_init.py b/tests/test_init.py index 59a5d02..fb5c304 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -33,7 +33,6 @@ def setup(mocker: MockFixture): mocker.patch.object(ACInfinity, "update", return_value=future) mocker.patch.object(ACInfinityClient, "__init__", return_value=None) mocker.patch.object(HomeAssistant, "__init__", return_value=None) - mocker.patch.object(ConfigEntry, "__init__", return_value=None) mocker.patch.object(ConfigEntries, "__init__", return_value=None) mocker.patch.object( ConfigEntries, "async_forward_entry_setups", return_value=future @@ -42,28 +41,34 @@ def setup(mocker: MockFixture): ConfigEntries, "async_unload_platforms", return_value=boolFuture ) - config_entry = ConfigEntry() - config_entry.entry_id = ENTRY_ID - config_entry.data = {CONF_EMAIL: EMAIL, CONF_PASSWORD: PASSWORD} + config_entry = ConfigEntry( + entry_id=ENTRY_ID, + data={CONF_EMAIL: EMAIL, CONF_PASSWORD: PASSWORD}, + domain=DOMAIN, + minor_version=0, + source="", + title="", + version=0, + ) hass = HomeAssistant("/path") hass.config_entries = ConfigEntries() hass.data = {} - return (hass, config_entry) + return hass, config_entry @pytest.mark.asyncio class TestInit: - async def test_async_setup_entry_aerogarden_init(self, setup): - """when setting up, aerogarden should be initialized and assigned to the hass object""" + async def test_async_setup_entry_ac_infinity_init(self, setup): + """when setting up, ac_infinity should be initialized and assigned to the hass object""" (hass, config_entry) = setup await async_setup_entry(hass, config_entry) assert hass.data[DOMAIN][ENTRY_ID] is not None - async def test_async_setup_entry_platforms_initalized(self, setup): + async def test_async_setup_entry_platforms_initialized(self, setup): """When setting up, all platforms should be initialized""" hass: HomeAssistant (hass, config_entry) = setup diff --git a/tests/test_number.py b/tests/test_number.py index c17bd11..ea3ae5f 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -55,7 +55,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) diff --git a/tests/test_select.py b/tests/test_select.py index 7472d78..5f9cf65 100644 --- a/tests/test_select.py +++ b/tests/test_select.py @@ -35,7 +35,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) diff --git a/tests/test_sensor.py b/tests/test_sensor.py index c6a6271..a74ef29 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -43,7 +43,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) diff --git a/tests/test_switch.py b/tests/test_switch.py index 9d208e1..802c373 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -43,7 +43,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, ) diff --git a/tests/test_time.py b/tests/test_time.py index 090372e..cb2ce08 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -34,7 +34,7 @@ async def test_async_setup_all_sensors_created(self, setup): await async_setup_entry( test_objects.hass, - test_objects.configEntry, + test_objects.config_entry, test_objects.entities.add_entities_callback, )