diff --git a/custom_components/openei/const.py b/custom_components/openei/const.py index 0d254dd..4c3701a 100644 --- a/custom_components/openei/const.py +++ b/custom_components/openei/const.py @@ -74,7 +74,6 @@ key="all_rates", name="All Listed Rates", icon="mdi:format-list-bulleted", - entity_category=EntityCategory.DIAGNOSTIC, ), "monthly_tier_rate": SensorEntityDescription( key="monthly_tier_rate", diff --git a/custom_components/openei/sensor.py b/custom_components/openei/sensor.py index 30fd95e..195e9f8 100644 --- a/custom_components/openei/sensor.py +++ b/custom_components/openei/sensor.py @@ -20,6 +20,8 @@ async def async_setup_entry(hass, entry, async_add_devices): sensors = [] for sensor in SENSOR_TYPES: + if sensor == "all_rates": + continue sensors.append(OpenEISensor(hass, SENSOR_TYPES[sensor], entry, coordinator)) async_add_devices(sensors, False) @@ -72,6 +74,8 @@ def extra_state_attributes(self) -> Optional[dict]: """Return sesnsor attributes.""" attrs = {} attrs[ATTR_ATTRIBUTION] = ATTRIBUTION + if self._key == "current_rate": + attrs["all_rates"] = self.coordinator.data.get("all_rates") return attrs @property diff --git a/tests/conftest.py b/tests/conftest.py index 75fa488..b63dafe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,6 +26,7 @@ def mock_api(): mock_api.return_value.lookup_plans = ( '"Fake Utility Co": [{"name": "Fake Plan Name", "label": "randomstring"}]' ) + mock_api.return_value.all_rates = [ 0.24477, 0.007 ] yield mock_api @@ -53,6 +54,7 @@ def mock_get_sensors(): "rate_name": "Fake Test Rate", "mincharge": 10, "mincharge_uom": "$/month", + "all_rates": [ 0.24477, 0.007 ], } yield mock_sensors diff --git a/tests/test_init.py b/tests/test_init.py index 5092c66..77ce150 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -24,7 +24,7 @@ async def test_setup_entry(hass, mock_sensors, mock_api): assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 @@ -42,14 +42,14 @@ async def test_unload_entry(hass, mock_sensors, mock_api): assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert await hass.config_entries.async_unload(entries[0].entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 assert len(hass.states.async_entity_ids(DOMAIN)) == 0 diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 785521f..5334112 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -6,6 +6,7 @@ from tests.const import CONFIG_DATA FAKE_MINCHARGE_SENSOR = "sensor.fake_utility_co_minimum_charge" +FAKE_CURRENT_RATE_SENSOR = "sensor.fake_utility_co_current_energy_rate" async def test_sensors(hass, mock_sensors, mock_api): @@ -24,3 +25,8 @@ async def test_sensors(hass, mock_sensors, mock_api): assert state is not None assert state.state == "10" assert state.attributes["unit_of_measurement"] == "$/month" + + state = hass.states.get(FAKE_CURRENT_RATE_SENSOR) + assert state is not None + assert state.state == "0.24477" + assert state.attributes["all_rates"] == [ 0.24477, 0.007 ]