Migrate spider to entity name (#96170)

pull/96872/head
Joost Lekkerkerker 2023-07-18 21:41:33 +02:00 committed by GitHub
parent a2495f494b
commit 2b3a379b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 20 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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"
}
}
}
}

View File

@ -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."""