Use shorthand attributes for freedompro (#95358)

pull/95394/head
Joost Lekkerkerker 2023-06-27 18:53:29 +02:00 committed by GitHub
parent b0834472bc
commit 0b32a6e0d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 26 deletions

View File

@ -44,7 +44,7 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], BinarySensorEntity):
"""Representation of an Freedompro binary_sensor."""
"""Representation of a Freedompro binary_sensor."""
_attr_has_entity_name = True
_attr_name = None

View File

@ -58,11 +58,16 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], ClimateEntity):
"""Representation of an Freedompro climate."""
"""Representation of a Freedompro climate."""
_attr_has_entity_name = True
_attr_hvac_modes = SUPPORTED_HVAC_MODES
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_name = None
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_current_temperature = 0
_attr_target_temperature = 0
_attr_hvac_mode = HVACMode.OFF
def __init__(
self,
@ -75,7 +80,6 @@ class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], ClimateEntity):
super().__init__(coordinator)
self._session = session
self._api_key = api_key
self._attr_name = None
self._attr_unique_id = device["uid"]
self._characteristics = device["characteristics"]
self._attr_device_info = DeviceInfo(
@ -86,10 +90,6 @@ class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], ClimateEntity):
model=device["type"],
name=device["name"],
)
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
self._attr_current_temperature = 0
self._attr_target_temperature = 0
self._attr_hvac_mode = HVACMode.OFF
@callback
def _handle_coordinator_update(self) -> None:
@ -122,8 +122,7 @@ class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], ClimateEntity):
if hvac_mode not in SUPPORTED_HVAC_MODES:
raise ValueError(f"Got unsupported hvac_mode {hvac_mode}")
payload = {}
payload["heatingCoolingState"] = HVAC_INVERT_MAP[hvac_mode]
payload = {"heatingCoolingState": HVAC_INVERT_MAP[hvac_mode]}
await put_state(
self._session,
self._api_key,

View File

@ -46,10 +46,17 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], CoverEntity):
"""Representation of an Freedompro cover."""
"""Representation of a Freedompro cover."""
_attr_has_entity_name = True
_attr_name = None
_attr_current_cover_position = 0
_attr_is_closed = True
_attr_supported_features = (
CoverEntityFeature.CLOSE
| CoverEntityFeature.OPEN
| CoverEntityFeature.SET_POSITION
)
def __init__(
self,
@ -71,13 +78,6 @@ class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], CoverEntity):
model=device["type"],
name=device["name"],
)
self._attr_current_cover_position = 0
self._attr_is_closed = True
self._attr_supported_features = (
CoverEntityFeature.CLOSE
| CoverEntityFeature.OPEN
| CoverEntityFeature.SET_POSITION
)
self._attr_device_class = DEVICE_CLASS_MAP[device["type"]]
@callback

View File

@ -33,10 +33,12 @@ async def async_setup_entry(
class FreedomproFan(CoordinatorEntity[FreedomproDataUpdateCoordinator], FanEntity):
"""Representation of an Freedompro fan."""
"""Representation of a Freedompro fan."""
_attr_has_entity_name = True
_attr_name = None
_attr_is_on = False
_attr_percentage = 0
def __init__(
self,
@ -59,8 +61,6 @@ class FreedomproFan(CoordinatorEntity[FreedomproDataUpdateCoordinator], FanEntit
model=device["type"],
name=device["name"],
)
self._attr_is_on = False
self._attr_percentage = 0
if "rotationSpeed" in self._characteristics:
self._attr_supported_features = FanEntityFeature.SET_SPEED

View File

@ -38,10 +38,12 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], LightEntity):
"""Representation of an Freedompro light."""
"""Representation of a Freedompro light."""
_attr_has_entity_name = True
_attr_name = None
_attr_is_on = False
_attr_brightness = 0
def __init__(
self,
@ -61,8 +63,6 @@ class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], LightEntity):
model=device["type"],
name=device["name"],
)
self._attr_is_on = False
self._attr_brightness = 0
color_mode = ColorMode.ONOFF
if "hue" in device["characteristics"]:
color_mode = ColorMode.HS

View File

@ -31,7 +31,7 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], LockEntity):
"""Representation of an Freedompro lock."""
"""Representation of a Freedompro lock."""
_attr_has_entity_name = True
_attr_name = None

View File

@ -52,7 +52,7 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], SensorEntity):
"""Representation of an Freedompro sensor."""
"""Representation of a Freedompro sensor."""
_attr_has_entity_name = True
_attr_name = None

View File

@ -31,7 +31,7 @@ async def async_setup_entry(
class Device(CoordinatorEntity[FreedomproDataUpdateCoordinator], SwitchEntity):
"""Representation of an Freedompro switch."""
"""Representation of a Freedompro switch."""
_attr_has_entity_name = True
_attr_name = None