From 2b3a379b8e8cca4687b9b2252567ed449fa2d44a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 18 Jul 2023 21:41:33 +0200 Subject: [PATCH] Migrate spider to entity name (#96170) --- homeassistant/components/spider/climate.py | 7 ++----- homeassistant/components/spider/sensor.py | 14 ++++---------- homeassistant/components/spider/strings.json | 10 ++++++++++ homeassistant/components/spider/switch.py | 8 +++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 261d1565160..2769d045c0b 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -40,6 +40,8 @@ async def async_setup_entry( class SpiderThermostat(ClimateEntity): """Representation of a thermostat.""" + _attr_has_entity_name = True + _attr_name = None _attr_temperature_unit = UnitOfTemperature.CELSIUS def __init__(self, api, thermostat): @@ -77,11 +79,6 @@ class SpiderThermostat(ClimateEntity): """Return the id of the thermostat, if any.""" return self.thermostat.id - @property - def name(self): - """Return the name of the thermostat, if any.""" - return self.thermostat.name - @property def current_temperature(self): """Return the current temperature.""" diff --git a/homeassistant/components/spider/sensor.py b/homeassistant/components/spider/sensor.py index 259c0fa4974..5b326db1e45 100644 --- a/homeassistant/components/spider/sensor.py +++ b/homeassistant/components/spider/sensor.py @@ -32,6 +32,8 @@ async def async_setup_entry( class SpiderPowerPlugEnergy(SensorEntity): """Representation of a Spider Power Plug (energy).""" + _attr_has_entity_name = True + _attr_translation_key = "total_energy_today" _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING @@ -56,11 +58,6 @@ class SpiderPowerPlugEnergy(SensorEntity): """Return the ID of this sensor.""" return f"{self.power_plug.id}_total_energy_today" - @property - def name(self) -> str: - """Return the name of the sensor if any.""" - return f"{self.power_plug.name} Total Energy Today" - @property def native_value(self) -> float: """Return todays energy usage in Kwh.""" @@ -74,6 +71,8 @@ class SpiderPowerPlugEnergy(SensorEntity): class SpiderPowerPlugPower(SensorEntity): """Representation of a Spider Power Plug (power).""" + _attr_has_entity_name = True + _attr_translation_key = "power_consumption" _attr_device_class = SensorDeviceClass.POWER _attr_state_class = SensorStateClass.MEASUREMENT _attr_native_unit_of_measurement = UnitOfPower.WATT @@ -98,11 +97,6 @@ class SpiderPowerPlugPower(SensorEntity): """Return the ID of this sensor.""" return f"{self.power_plug.id}_power_consumption" - @property - def name(self) -> str: - """Return the name of the sensor if any.""" - return f"{self.power_plug.name} Power Consumption" - @property def native_value(self) -> float: """Return the current power usage in W.""" diff --git a/homeassistant/components/spider/strings.json b/homeassistant/components/spider/strings.json index 2e86f47dd2d..c8d67be36ae 100644 --- a/homeassistant/components/spider/strings.json +++ b/homeassistant/components/spider/strings.json @@ -16,5 +16,15 @@ "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } + }, + "entity": { + "sensor": { + "power_consumption": { + "name": "Power consumption" + }, + "total_energy_today": { + "name": "Total energy today" + } + } } } diff --git a/homeassistant/components/spider/switch.py b/homeassistant/components/spider/switch.py index 607e4c5b84a..28bbf0fcc18 100644 --- a/homeassistant/components/spider/switch.py +++ b/homeassistant/components/spider/switch.py @@ -26,6 +26,9 @@ async def async_setup_entry( class SpiderPowerPlug(SwitchEntity): """Representation of a Spider Power Plug.""" + _attr_has_entity_name = True + _attr_name = None + def __init__(self, api, power_plug): """Initialize the Spider Power Plug.""" self.api = api @@ -47,11 +50,6 @@ class SpiderPowerPlug(SwitchEntity): """Return the ID of this switch.""" return self.power_plug.id - @property - def name(self): - """Return the name of the switch if any.""" - return self.power_plug.name - @property def is_on(self): """Return true if switch is on. Standby is on."""