From 6fdb414b58ec11a809d7c2ce9566797824faa62c Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Mon, 18 Jul 2022 06:12:13 -0400 Subject: [PATCH] Migrate Goalzero to new entity naming style (#75358) --- .../components/goalzero/binary_sensor.py | 4 ++-- homeassistant/components/goalzero/entity.py | 6 ++--- homeassistant/components/goalzero/sensor.py | 22 +++++++++---------- homeassistant/components/goalzero/switch.py | 6 ++--- tests/components/goalzero/test_sensor.py | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/goalzero/binary_sensor.py b/homeassistant/components/goalzero/binary_sensor.py index c4219b51e6c..db8a1b788f2 100644 --- a/homeassistant/components/goalzero/binary_sensor.py +++ b/homeassistant/components/goalzero/binary_sensor.py @@ -26,7 +26,7 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = ( ), BinarySensorEntityDescription( key="app_online", - name="App Online", + name="App online", device_class=BinarySensorDeviceClass.CONNECTIVITY, entity_category=EntityCategory.DIAGNOSTIC, ), @@ -37,7 +37,7 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = ( ), BinarySensorEntityDescription( key="inputDetected", - name="Input Detected", + name="Input detected", device_class=BinarySensorDeviceClass.POWER, ), ) diff --git a/homeassistant/components/goalzero/entity.py b/homeassistant/components/goalzero/entity.py index 8c696ce1377..eef6ea43d9c 100644 --- a/homeassistant/components/goalzero/entity.py +++ b/homeassistant/components/goalzero/entity.py @@ -15,6 +15,7 @@ class GoalZeroEntity(CoordinatorEntity[GoalZeroDataUpdateCoordinator]): """Representation of a Goal Zero Yeti entity.""" _attr_attribution = ATTRIBUTION + _attr_has_entity_name = True def __init__( self, @@ -24,9 +25,6 @@ class GoalZeroEntity(CoordinatorEntity[GoalZeroDataUpdateCoordinator]): """Initialize a Goal Zero Yeti entity.""" super().__init__(coordinator) self.entity_description = description - self._attr_name = ( - f"{coordinator.config_entry.data[CONF_NAME]} {description.name}" - ) self._attr_unique_id = f"{coordinator.config_entry.entry_id}/{description.key}" @property @@ -37,7 +35,7 @@ class GoalZeroEntity(CoordinatorEntity[GoalZeroDataUpdateCoordinator]): identifiers={(DOMAIN, self.coordinator.config_entry.entry_id)}, manufacturer=MANUFACTURER, model=self._api.sysdata[ATTR_MODEL], - name=self.coordinator.config_entry.data[CONF_NAME], + name=self.coordinator.config_entry.data[CONF_NAME].capitalize(), sw_version=self._api.data["firmwareVersion"], ) diff --git a/homeassistant/components/goalzero/sensor.py b/homeassistant/components/goalzero/sensor.py index ef95578820d..345c3b41f7d 100644 --- a/homeassistant/components/goalzero/sensor.py +++ b/homeassistant/components/goalzero/sensor.py @@ -32,14 +32,14 @@ from .entity import GoalZeroEntity SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="wattsIn", - name="Watts In", + name="Watts in", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=POWER_WATT, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="ampsIn", - name="Amps In", + name="Amps in", device_class=SensorDeviceClass.CURRENT, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, state_class=SensorStateClass.MEASUREMENT, @@ -47,14 +47,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="wattsOut", - name="Watts Out", + name="Watts out", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=POWER_WATT, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key="ampsOut", - name="Amps Out", + name="Amps out", device_class=SensorDeviceClass.CURRENT, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, state_class=SensorStateClass.MEASUREMENT, @@ -62,7 +62,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="whOut", - name="WH Out", + name="Wh out", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, @@ -70,7 +70,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="whStored", - name="WH Stored", + name="Wh stored", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_WATT_HOUR, state_class=SensorStateClass.MEASUREMENT, @@ -84,13 +84,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="socPercent", - name="State of Charge Percent", + name="State of charge percent", device_class=SensorDeviceClass.BATTERY, native_unit_of_measurement=PERCENTAGE, ), SensorEntityDescription( key="timeToEmptyFull", - name="Time to Empty/Full", + name="Time to empty/full", device_class=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES, ), @@ -103,7 +103,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="wifiStrength", - name="Wifi Strength", + name="Wi-Fi strength", device_class=SensorDeviceClass.SIGNAL_STRENGTH, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, entity_registry_enabled_default=False, @@ -111,7 +111,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="timestamp", - name="Total Run Time", + name="Total run time", native_unit_of_measurement=TIME_SECONDS, entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, @@ -124,7 +124,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="ipAddr", - name="IP Address", + name="IP address", entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), diff --git a/homeassistant/components/goalzero/switch.py b/homeassistant/components/goalzero/switch.py index 9a58cb385b6..25fdeb52114 100644 --- a/homeassistant/components/goalzero/switch.py +++ b/homeassistant/components/goalzero/switch.py @@ -14,15 +14,15 @@ from .entity import GoalZeroEntity SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = ( SwitchEntityDescription( key="v12PortStatus", - name="12V Port Status", + name="12V port status", ), SwitchEntityDescription( key="usbPortStatus", - name="USB Port Status", + name="USB port status", ), SwitchEntityDescription( key="acPortStatus", - name="AC Port Status", + name="AC port status", ), ) diff --git a/tests/components/goalzero/test_sensor.py b/tests/components/goalzero/test_sensor.py index ce67351c978..e61015a4925 100644 --- a/tests/components/goalzero/test_sensor.py +++ b/tests/components/goalzero/test_sensor.py @@ -85,7 +85,7 @@ async def test_sensors( assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS assert state.attributes.get(ATTR_STATE_CLASS) is None - state = hass.states.get(f"sensor.{DEFAULT_NAME}_wifi_strength") + state = hass.states.get(f"sensor.{DEFAULT_NAME}_wi_fi_strength") assert state.state == "-62" assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.SIGNAL_STRENGTH assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_STRENGTH_DECIBELS