mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use shorthand attributes in Smappee (#99837)
This commit is contained in:
parent
6692a37f0d
commit
923d945267
@ -15,6 +15,23 @@ from .const import DOMAIN
|
|||||||
BINARY_SENSOR_PREFIX = "Appliance"
|
BINARY_SENSOR_PREFIX = "Appliance"
|
||||||
PRESENCE_PREFIX = "Presence"
|
PRESENCE_PREFIX = "Presence"
|
||||||
|
|
||||||
|
ICON_MAPPING = {
|
||||||
|
"Car Charger": "mdi:car",
|
||||||
|
"Coffeemaker": "mdi:coffee",
|
||||||
|
"Clothes Dryer": "mdi:tumble-dryer",
|
||||||
|
"Clothes Iron": "mdi:hanger",
|
||||||
|
"Dishwasher": "mdi:dishwasher",
|
||||||
|
"Lights": "mdi:lightbulb",
|
||||||
|
"Fan": "mdi:fan",
|
||||||
|
"Freezer": "mdi:fridge",
|
||||||
|
"Microwave": "mdi:microwave",
|
||||||
|
"Oven": "mdi:stove",
|
||||||
|
"Refrigerator": "mdi:fridge",
|
||||||
|
"Stove": "mdi:stove",
|
||||||
|
"Washing Machine": "mdi:washing-machine",
|
||||||
|
"Water Pump": "mdi:water-pump",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -48,54 +65,33 @@ async def async_setup_entry(
|
|||||||
class SmappeePresence(BinarySensorEntity):
|
class SmappeePresence(BinarySensorEntity):
|
||||||
"""Implementation of a Smappee presence binary sensor."""
|
"""Implementation of a Smappee presence binary sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = BinarySensorDeviceClass.PRESENCE
|
||||||
|
|
||||||
def __init__(self, smappee_base, service_location):
|
def __init__(self, smappee_base, service_location):
|
||||||
"""Initialize the Smappee sensor."""
|
"""Initialize the Smappee sensor."""
|
||||||
self._smappee_base = smappee_base
|
self._smappee_base = smappee_base
|
||||||
self._service_location = service_location
|
self._service_location = service_location
|
||||||
self._state = self._service_location.is_present
|
self._attr_name = (
|
||||||
|
f"{service_location.service_location_name} - {PRESENCE_PREFIX}"
|
||||||
@property
|
)
|
||||||
def name(self):
|
self._attr_unique_id = (
|
||||||
"""Return the name of the binary sensor."""
|
f"{service_location.device_serial_number}-"
|
||||||
return f"{self._service_location.service_location_name} - {PRESENCE_PREFIX}"
|
f"{service_location.service_location_id}-"
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return if the binary sensor is turned on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return BinarySensorDeviceClass.PRESENCE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(
|
|
||||||
self,
|
|
||||||
):
|
|
||||||
"""Return the unique ID for this binary sensor."""
|
|
||||||
return (
|
|
||||||
f"{self._service_location.device_serial_number}-"
|
|
||||||
f"{self._service_location.service_location_id}-"
|
|
||||||
f"{BinarySensorDeviceClass.PRESENCE}"
|
f"{BinarySensorDeviceClass.PRESENCE}"
|
||||||
)
|
)
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
@property
|
identifiers={(DOMAIN, service_location.device_serial_number)},
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info for this binary sensor."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._service_location.device_serial_number)},
|
|
||||||
manufacturer="Smappee",
|
manufacturer="Smappee",
|
||||||
model=self._service_location.device_model,
|
model=service_location.device_model,
|
||||||
name=self._service_location.service_location_name,
|
name=service_location.service_location_name,
|
||||||
sw_version=self._service_location.firmware_version,
|
sw_version=service_location.firmware_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get the latest data from Smappee and update the state."""
|
"""Get the latest data from Smappee and update the state."""
|
||||||
await self._smappee_base.async_update()
|
await self._smappee_base.async_update()
|
||||||
|
|
||||||
self._state = self._service_location.is_present
|
self._attr_is_on = self._service_location.is_present
|
||||||
|
|
||||||
|
|
||||||
class SmappeeAppliance(BinarySensorEntity):
|
class SmappeeAppliance(BinarySensorEntity):
|
||||||
@ -113,70 +109,28 @@ class SmappeeAppliance(BinarySensorEntity):
|
|||||||
self._smappee_base = smappee_base
|
self._smappee_base = smappee_base
|
||||||
self._service_location = service_location
|
self._service_location = service_location
|
||||||
self._appliance_id = appliance_id
|
self._appliance_id = appliance_id
|
||||||
self._appliance_name = appliance_name
|
self._attr_name = (
|
||||||
self._appliance_type = appliance_type
|
f"{service_location.service_location_name} - "
|
||||||
self._state = False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return (
|
|
||||||
f"{self._service_location.service_location_name} - "
|
|
||||||
f"{BINARY_SENSOR_PREFIX} - "
|
f"{BINARY_SENSOR_PREFIX} - "
|
||||||
f"{self._appliance_name if self._appliance_name != '' else self._appliance_type}"
|
f"{appliance_name if appliance_name != '' else appliance_type}"
|
||||||
)
|
)
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f"{service_location.device_serial_number}-"
|
||||||
def is_on(self):
|
f"{service_location.service_location_id}-"
|
||||||
"""Return if the binary sensor is turned on."""
|
f"appliance-{appliance_id}"
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
icon_mapping = {
|
|
||||||
"Car Charger": "mdi:car",
|
|
||||||
"Coffeemaker": "mdi:coffee",
|
|
||||||
"Clothes Dryer": "mdi:tumble-dryer",
|
|
||||||
"Clothes Iron": "mdi:hanger",
|
|
||||||
"Dishwasher": "mdi:dishwasher",
|
|
||||||
"Lights": "mdi:lightbulb",
|
|
||||||
"Fan": "mdi:fan",
|
|
||||||
"Freezer": "mdi:fridge",
|
|
||||||
"Microwave": "mdi:microwave",
|
|
||||||
"Oven": "mdi:stove",
|
|
||||||
"Refrigerator": "mdi:fridge",
|
|
||||||
"Stove": "mdi:stove",
|
|
||||||
"Washing Machine": "mdi:washing-machine",
|
|
||||||
"Water Pump": "mdi:water-pump",
|
|
||||||
}
|
|
||||||
return icon_mapping.get(self._appliance_type)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(
|
|
||||||
self,
|
|
||||||
):
|
|
||||||
"""Return the unique ID for this binary sensor."""
|
|
||||||
return (
|
|
||||||
f"{self._service_location.device_serial_number}-"
|
|
||||||
f"{self._service_location.service_location_id}-"
|
|
||||||
f"appliance-{self._appliance_id}"
|
|
||||||
)
|
)
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
@property
|
identifiers={(DOMAIN, service_location.device_serial_number)},
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info for this binary sensor."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._service_location.device_serial_number)},
|
|
||||||
manufacturer="Smappee",
|
manufacturer="Smappee",
|
||||||
model=self._service_location.device_model,
|
model=service_location.device_model,
|
||||||
name=self._service_location.service_location_name,
|
name=service_location.service_location_name,
|
||||||
sw_version=self._service_location.firmware_version,
|
sw_version=service_location.firmware_version,
|
||||||
)
|
)
|
||||||
|
self._attr_icon = ICON_MAPPING.get(appliance_type)
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get the latest data from Smappee and update the state."""
|
"""Get the latest data from Smappee and update the state."""
|
||||||
await self._smappee_base.async_update()
|
await self._smappee_base.async_update()
|
||||||
|
|
||||||
appliance = self._service_location.appliances.get(self._appliance_id)
|
appliance = self._service_location.appliances.get(self._appliance_id)
|
||||||
self._state = bool(appliance.state)
|
self._attr_is_on = bool(appliance.state)
|
||||||
|
@ -341,6 +341,13 @@ class SmappeeSensor(SensorEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._smappee_base = smappee_base
|
self._smappee_base = smappee_base
|
||||||
self._service_location = service_location
|
self._service_location = service_location
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, service_location.device_serial_number)},
|
||||||
|
manufacturer="Smappee",
|
||||||
|
model=service_location.device_model,
|
||||||
|
name=service_location.service_location_name,
|
||||||
|
sw_version=service_location.firmware_version,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -372,17 +379,6 @@ class SmappeeSensor(SensorEntity):
|
|||||||
f"{sensor_key}"
|
f"{sensor_key}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info for this sensor."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._service_location.device_serial_number)},
|
|
||||||
manufacturer="Smappee",
|
|
||||||
model=self._service_location.device_model,
|
|
||||||
name=self._service_location.service_location_name,
|
|
||||||
sw_version=self._service_location.firmware_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get the latest data from Smappee and update the state."""
|
"""Get the latest data from Smappee and update the state."""
|
||||||
await self._smappee_base.async_update()
|
await self._smappee_base.async_update()
|
||||||
|
@ -74,10 +74,17 @@ class SmappeeActuator(SwitchEntity):
|
|||||||
self._actuator_type = actuator_type
|
self._actuator_type = actuator_type
|
||||||
self._actuator_serialnumber = actuator_serialnumber
|
self._actuator_serialnumber = actuator_serialnumber
|
||||||
self._actuator_state_option = actuator_state_option
|
self._actuator_state_option = actuator_state_option
|
||||||
self._state = self._service_location.actuators.get(actuator_id).state
|
self._state = service_location.actuators.get(actuator_id).state
|
||||||
self._connection_state = self._service_location.actuators.get(
|
self._connection_state = service_location.actuators.get(
|
||||||
actuator_id
|
actuator_id
|
||||||
).connection_state
|
).connection_state
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, service_location.device_serial_number)},
|
||||||
|
manufacturer="Smappee",
|
||||||
|
model=service_location.device_model,
|
||||||
|
name=service_location.service_location_name,
|
||||||
|
sw_version=service_location.firmware_version,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -153,17 +160,6 @@ class SmappeeActuator(SwitchEntity):
|
|||||||
f"{self._actuator_id}"
|
f"{self._actuator_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info for this switch."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._service_location.device_serial_number)},
|
|
||||||
manufacturer="Smappee",
|
|
||||||
model=self._service_location.device_model,
|
|
||||||
name=self._service_location.service_location_name,
|
|
||||||
sw_version=self._service_location.firmware_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get the latest data from Smappee and update the state."""
|
"""Get the latest data from Smappee and update the state."""
|
||||||
await self._smappee_base.async_update()
|
await self._smappee_base.async_update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user