mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use shorthand attributes in Gree (#99332)
This commit is contained in:
parent
66ad605d3e
commit
587928223a
@ -115,40 +115,33 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
| ClimateEntityFeature.PRESET_MODE
|
| ClimateEntityFeature.PRESET_MODE
|
||||||
| ClimateEntityFeature.SWING_MODE
|
| ClimateEntityFeature.SWING_MODE
|
||||||
)
|
)
|
||||||
|
_attr_target_temperature_step = TARGET_TEMPERATURE_STEP
|
||||||
|
_attr_hvac_modes = [*HVAC_MODES_REVERSE, HVACMode.OFF]
|
||||||
|
_attr_preset_modes = PRESET_MODES
|
||||||
|
_attr_fan_modes = [*FAN_MODES_REVERSE]
|
||||||
|
_attr_swing_modes = SWING_MODES
|
||||||
|
|
||||||
def __init__(self, coordinator: DeviceDataUpdateCoordinator) -> None:
|
def __init__(self, coordinator: DeviceDataUpdateCoordinator) -> None:
|
||||||
"""Initialize the Gree device."""
|
"""Initialize the Gree device."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._name = coordinator.device.device_info.name
|
self._attr_name = coordinator.device.device_info.name
|
||||||
self._mac = coordinator.device.device_info.mac
|
mac = coordinator.device.device_info.mac
|
||||||
|
self._attr_unique_id = mac
|
||||||
@property
|
self._attr_device_info = DeviceInfo(
|
||||||
def name(self) -> str:
|
connections={(CONNECTION_NETWORK_MAC, mac)},
|
||||||
"""Return the name of the device."""
|
identifiers={(DOMAIN, mac)},
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique id for the device."""
|
|
||||||
return self._mac
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device specific attributes."""
|
|
||||||
return DeviceInfo(
|
|
||||||
connections={(CONNECTION_NETWORK_MAC, self._mac)},
|
|
||||||
identifiers={(DOMAIN, self._mac)},
|
|
||||||
manufacturer="Gree",
|
manufacturer="Gree",
|
||||||
name=self._name,
|
name=self._attr_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def temperature_unit(self) -> str:
|
|
||||||
"""Return the temperature units for the device."""
|
|
||||||
units = self.coordinator.device.temperature_units
|
units = self.coordinator.device.temperature_units
|
||||||
if units == TemperatureUnits.C:
|
if units == TemperatureUnits.C:
|
||||||
return UnitOfTemperature.CELSIUS
|
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
return UnitOfTemperature.FAHRENHEIT
|
self._attr_min_temp = TEMP_MIN
|
||||||
|
self._attr_max_temp = TEMP_MAX
|
||||||
|
else:
|
||||||
|
self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||||
|
self._attr_min_temp = TEMP_MIN_F
|
||||||
|
self._attr_max_temp = TEMP_MAX_F
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self) -> float:
|
def current_temperature(self) -> float:
|
||||||
@ -169,32 +162,13 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting temperature to %d for %s",
|
"Setting temperature to %d for %s",
|
||||||
temperature,
|
temperature,
|
||||||
self._name,
|
self._attr_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.coordinator.device.target_temperature = round(temperature)
|
self.coordinator.device.target_temperature = round(temperature)
|
||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def min_temp(self) -> float:
|
|
||||||
"""Return the minimum temperature supported by the device."""
|
|
||||||
if self.temperature_unit == UnitOfTemperature.CELSIUS:
|
|
||||||
return TEMP_MIN
|
|
||||||
return TEMP_MIN_F
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_temp(self) -> float:
|
|
||||||
"""Return the maximum temperature supported by the device."""
|
|
||||||
if self.temperature_unit == UnitOfTemperature.CELSIUS:
|
|
||||||
return TEMP_MAX
|
|
||||||
return TEMP_MAX_F
|
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature_step(self) -> float:
|
|
||||||
"""Return the target temperature step support by the device."""
|
|
||||||
return TARGET_TEMPERATURE_STEP
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> HVACMode | None:
|
def hvac_mode(self) -> HVACMode | None:
|
||||||
"""Return the current HVAC mode for the device."""
|
"""Return the current HVAC mode for the device."""
|
||||||
@ -211,7 +185,7 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting HVAC mode to %s for device %s",
|
"Setting HVAC mode to %s for device %s",
|
||||||
hvac_mode,
|
hvac_mode,
|
||||||
self._name,
|
self._attr_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
if hvac_mode == HVACMode.OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
@ -229,7 +203,7 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the device."""
|
"""Turn on the device."""
|
||||||
_LOGGER.debug("Turning on HVAC for device %s", self._name)
|
_LOGGER.debug("Turning on HVAC for device %s", self._attr_name)
|
||||||
|
|
||||||
self.coordinator.device.power = True
|
self.coordinator.device.power = True
|
||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
@ -237,19 +211,12 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the device."""
|
"""Turn off the device."""
|
||||||
_LOGGER.debug("Turning off HVAC for device %s", self._name)
|
_LOGGER.debug("Turning off HVAC for device %s", self._attr_name)
|
||||||
|
|
||||||
self.coordinator.device.power = False
|
self.coordinator.device.power = False
|
||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self) -> list[HVACMode]:
|
|
||||||
"""Return the HVAC modes support by the device."""
|
|
||||||
modes = [*HVAC_MODES_REVERSE]
|
|
||||||
modes.append(HVACMode.OFF)
|
|
||||||
return modes
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_mode(self) -> str:
|
def preset_mode(self) -> str:
|
||||||
"""Return the current preset mode for the device."""
|
"""Return the current preset mode for the device."""
|
||||||
@ -271,7 +238,7 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting preset mode to %s for device %s",
|
"Setting preset mode to %s for device %s",
|
||||||
preset_mode,
|
preset_mode,
|
||||||
self._name,
|
self._attr_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.coordinator.device.steady_heat = False
|
self.coordinator.device.steady_heat = False
|
||||||
@ -291,11 +258,6 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_modes(self) -> list[str]:
|
|
||||||
"""Return the preset modes support by the device."""
|
|
||||||
return PRESET_MODES
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self) -> str | None:
|
def fan_mode(self) -> str | None:
|
||||||
"""Return the current fan mode for the device."""
|
"""Return the current fan mode for the device."""
|
||||||
@ -311,11 +273,6 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def fan_modes(self) -> list[str]:
|
|
||||||
"""Return the fan modes support by the device."""
|
|
||||||
return [*FAN_MODES_REVERSE]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def swing_mode(self) -> str:
|
def swing_mode(self) -> str:
|
||||||
"""Return the current swing mode for the device."""
|
"""Return the current swing mode for the device."""
|
||||||
@ -338,7 +295,7 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting swing mode to %s for device %s",
|
"Setting swing mode to %s for device %s",
|
||||||
swing_mode,
|
swing_mode,
|
||||||
self._name,
|
self._attr_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.coordinator.device.horizontal_swing = HorizontalSwing.Center
|
self.coordinator.device.horizontal_swing = HorizontalSwing.Center
|
||||||
@ -350,8 +307,3 @@ class GreeClimateEntity(CoordinatorEntity[DeviceDataUpdateCoordinator], ClimateE
|
|||||||
|
|
||||||
await self.coordinator.push_state_update()
|
await self.coordinator.push_state_update()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def swing_modes(self) -> list[str]:
|
|
||||||
"""Return the swing modes currently supported for this device."""
|
|
||||||
return SWING_MODES
|
|
||||||
|
@ -13,25 +13,13 @@ class GreeEntity(CoordinatorEntity[DeviceDataUpdateCoordinator]):
|
|||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._desc = desc
|
self._desc = desc
|
||||||
self._name = f"{coordinator.device.device_info.name}"
|
name = coordinator.device.device_info.name
|
||||||
self._mac = coordinator.device.device_info.mac
|
mac = coordinator.device.device_info.mac
|
||||||
|
self._attr_name = f"{name} {desc}"
|
||||||
@property
|
self._attr_unique_id = f"{mac}_{desc}"
|
||||||
def name(self):
|
self._attr_device_info = DeviceInfo(
|
||||||
"""Return the name of the node."""
|
connections={(CONNECTION_NETWORK_MAC, mac)},
|
||||||
return f"{self._name} {self._desc}"
|
identifiers={(DOMAIN, mac)},
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique id based for the node."""
|
|
||||||
return f"{self._mac}_{self._desc}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return info about the device."""
|
|
||||||
return DeviceInfo(
|
|
||||||
connections={(CONNECTION_NETWORK_MAC, self._mac)},
|
|
||||||
identifiers={(DOMAIN, self._mac)},
|
|
||||||
manufacturer="Gree",
|
manufacturer="Gree",
|
||||||
name=self._name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user