diff --git a/homeassistant/components/forecast_solar/const.py b/homeassistant/components/forecast_solar/const.py index d9742cf5dfc..185025fb5ce 100644 --- a/homeassistant/components/forecast_solar/const.py +++ b/homeassistant/components/forecast_solar/const.py @@ -19,31 +19,31 @@ CONF_INVERTER_SIZE = "inverter_size" SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( ForecastSolarSensorEntityDescription( key="energy_production_today", - name="Estimated Energy Production - Today", + name="Estimated energy production - today", state=lambda estimate: estimate.energy_production_today / 1000, device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), ForecastSolarSensorEntityDescription( key="energy_production_tomorrow", - name="Estimated Energy Production - Tomorrow", + name="Estimated energy production - tomorrow", state=lambda estimate: estimate.energy_production_tomorrow / 1000, device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), ForecastSolarSensorEntityDescription( key="power_highest_peak_time_today", - name="Highest Power Peak Time - Today", + name="Highest power peak time - today", device_class=SensorDeviceClass.TIMESTAMP, ), ForecastSolarSensorEntityDescription( key="power_highest_peak_time_tomorrow", - name="Highest Power Peak Time - Tomorrow", + name="Highest power peak time - tomorrow", device_class=SensorDeviceClass.TIMESTAMP, ), ForecastSolarSensorEntityDescription( key="power_production_now", - name="Estimated Power Production - Now", + name="Estimated power production - now", device_class=SensorDeviceClass.POWER, state=lambda estimate: estimate.power_production_now, state_class=SensorStateClass.MEASUREMENT, @@ -54,7 +54,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( state=lambda estimate: estimate.power_production_at_time( estimate.now() + timedelta(hours=1) ), - name="Estimated Power Production - Next Hour", + name="Estimated power production - next hour", device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, @@ -64,7 +64,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( state=lambda estimate: estimate.power_production_at_time( estimate.now() + timedelta(hours=12) ), - name="Estimated Power Production - Next 12 Hours", + name="Estimated power production - next 12 hours", device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, @@ -74,14 +74,14 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( state=lambda estimate: estimate.power_production_at_time( estimate.now() + timedelta(hours=24) ), - name="Estimated Power Production - Next 24 Hours", + name="Estimated power production - next 24 hours", device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, ), ForecastSolarSensorEntityDescription( key="energy_current_hour", - name="Estimated Energy Production - This Hour", + name="Estimated energy production - this hour", state=lambda estimate: estimate.energy_current_hour / 1000, device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, @@ -89,7 +89,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( ForecastSolarSensorEntityDescription( key="energy_next_hour", state=lambda estimate: estimate.sum_energy_production(1) / 1000, - name="Estimated Energy Production - Next Hour", + name="Estimated energy production - next hour", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), diff --git a/homeassistant/components/forecast_solar/sensor.py b/homeassistant/components/forecast_solar/sensor.py index 78335292a78..7bac69b1b6e 100644 --- a/homeassistant/components/forecast_solar/sensor.py +++ b/homeassistant/components/forecast_solar/sensor.py @@ -39,6 +39,7 @@ class ForecastSolarSensorEntity(CoordinatorEntity, SensorEntity): """Defines a Forecast.Solar sensor.""" entity_description: ForecastSolarSensorEntityDescription + _attr_has_entity_name = True def __init__( self, @@ -58,7 +59,7 @@ class ForecastSolarSensorEntity(CoordinatorEntity, SensorEntity): identifiers={(DOMAIN, entry_id)}, manufacturer="Forecast.Solar", model=coordinator.data.account_type.value, - name="Solar Production Forecast", + name="Solar production forecast", configuration_url="https://forecast.solar", ) diff --git a/tests/components/forecast_solar/test_sensor.py b/tests/components/forecast_solar/test_sensor.py index a05acb5bc16..893730c722e 100644 --- a/tests/components/forecast_solar/test_sensor.py +++ b/tests/components/forecast_solar/test_sensor.py @@ -41,7 +41,7 @@ async def test_sensors( assert state.state == "100.0" assert ( state.attributes.get(ATTR_FRIENDLY_NAME) - == "Estimated Energy Production - Today" + == "Solar production forecast Estimated energy production - today" ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR @@ -56,7 +56,7 @@ async def test_sensors( assert state.state == "200.0" assert ( state.attributes.get(ATTR_FRIENDLY_NAME) - == "Estimated Energy Production - Tomorrow" + == "Solar production forecast Estimated energy production - tomorrow" ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR @@ -69,7 +69,10 @@ async def test_sensors( assert state assert entry.unique_id == f"{entry_id}_power_highest_peak_time_today" assert state.state == "2021-06-27T20:00:00+00:00" # Timestamp sensor is UTC - assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Today" + assert ( + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Solar production forecast Highest power peak time - today" + ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes @@ -82,7 +85,8 @@ async def test_sensors( assert entry.unique_id == f"{entry_id}_power_highest_peak_time_tomorrow" assert state.state == "2021-06-27T21:00:00+00:00" # Timestamp sensor is UTC assert ( - state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Tomorrow" + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Solar production forecast Highest power peak time - tomorrow" ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP @@ -96,7 +100,8 @@ async def test_sensors( assert entry.unique_id == f"{entry_id}_power_production_now" assert state.state == "300000" assert ( - state.attributes.get(ATTR_FRIENDLY_NAME) == "Estimated Power Production - Now" + state.attributes.get(ATTR_FRIENDLY_NAME) + == "Solar production forecast Estimated power production - now" ) assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT @@ -111,7 +116,7 @@ async def test_sensors( assert state.state == "800.0" assert ( state.attributes.get(ATTR_FRIENDLY_NAME) - == "Estimated Energy Production - This Hour" + == "Solar production forecast Estimated energy production - this hour" ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR @@ -126,7 +131,7 @@ async def test_sensors( assert state.state == "900.0" assert ( state.attributes.get(ATTR_FRIENDLY_NAME) - == "Estimated Energy Production - Next Hour" + == "Solar production forecast Estimated energy production - next hour" ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR @@ -138,7 +143,7 @@ async def test_sensors( assert device_entry assert device_entry.identifiers == {(DOMAIN, f"{entry_id}")} assert device_entry.manufacturer == "Forecast.Solar" - assert device_entry.name == "Solar Production Forecast" + assert device_entry.name == "Solar production forecast" assert device_entry.entry_type is dr.DeviceEntryType.SERVICE assert device_entry.model == "public" assert not device_entry.sw_version @@ -172,17 +177,17 @@ async def test_disabled_by_default( [ ( "power_production_next_12hours", - "Estimated Power Production - Next 12 Hours", + "Estimated power production - next 12 hours", "600000", ), ( "power_production_next_24hours", - "Estimated Power Production - Next 24 Hours", + "Estimated power production - next 24 hours", "700000", ), ( "power_production_next_hour", - "Estimated Power Production - Next Hour", + "Estimated power production - next hour", "400000", ), ], @@ -219,7 +224,9 @@ async def test_enabling_disable_by_default( assert state assert entry.unique_id == f"{entry_id}_{key}" assert state.state == value - assert state.attributes.get(ATTR_FRIENDLY_NAME) == name + assert ( + state.attributes.get(ATTR_FRIENDLY_NAME) == f"Solar production forecast {name}" + ) assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER