mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Small code styling tweaks for Tuya (#57102)
This commit is contained in:
parent
5b218d7e1c
commit
80a04124a2
@ -46,10 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data[DOMAIN] = {entry.entry_id: {TUYA_HA_TUYA_MAP: {}, TUYA_HA_DEVICES: set()}}
|
hass.data[DOMAIN] = {entry.entry_id: {TUYA_HA_TUYA_MAP: {}, TUYA_HA_DEVICES: set()}}
|
||||||
|
|
||||||
success = await _init_tuya_sdk(hass, entry)
|
success = await _init_tuya_sdk(hass, entry)
|
||||||
if not success:
|
return bool(success)
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def _init_tuya_sdk(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def _init_tuya_sdk(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
@ -24,10 +24,9 @@ class TuyaHaEntity(Entity):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def remap(old_value, old_min, old_max, new_min, new_max):
|
def remap(old_value, old_min, old_max, new_min, new_max):
|
||||||
"""Remap old_value to new_value."""
|
"""Remap old_value to new_value."""
|
||||||
new_value = ((old_value - old_min) / (old_max - old_min)) * (
|
return ((old_value - old_min) / (old_max - old_min)) * (
|
||||||
new_max - new_min
|
new_max - new_min
|
||||||
) + new_min
|
) + new_min
|
||||||
return new_value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self) -> bool:
|
def should_poll(self) -> bool:
|
||||||
@ -47,13 +46,12 @@ class TuyaHaEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return a device description for device registry."""
|
"""Return a device description for device registry."""
|
||||||
_device_info = {
|
return {
|
||||||
"identifiers": {(DOMAIN, f"{self.tuya_device.id}")},
|
"identifiers": {(DOMAIN, f"{self.tuya_device.id}")},
|
||||||
"manufacturer": "Tuya",
|
"manufacturer": "Tuya",
|
||||||
"name": self.tuya_device.name,
|
"name": self.tuya_device.name,
|
||||||
"model": self.tuya_device.product_name,
|
"model": self.tuya_device.product_name,
|
||||||
}
|
}
|
||||||
return _device_info
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
@ -430,10 +430,10 @@ class TuyaHaClimate(TuyaHaEntity, ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def fan_modes(self) -> list[str]:
|
def fan_modes(self) -> list[str]:
|
||||||
"""Return fan modes for select."""
|
"""Return fan modes for select."""
|
||||||
data = json.loads(
|
fan_speed_device_function = self.tuya_device.function.get(DPCODE_FAN_SPEED_ENUM)
|
||||||
self.tuya_device.function.get(DPCODE_FAN_SPEED_ENUM, {}).values
|
if not fan_speed_device_function:
|
||||||
).get("range")
|
return []
|
||||||
return data
|
return json.loads(fan_speed_device_function.values).get("range", [])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def swing_mode(self) -> str:
|
def swing_mode(self) -> str:
|
||||||
|
@ -299,7 +299,7 @@ class TuyaHaLight(TuyaHaEntity, LightEntity):
|
|||||||
"""Return the color_temp of the light."""
|
"""Return the color_temp of the light."""
|
||||||
new_range = self._tuya_temp_range()
|
new_range = self._tuya_temp_range()
|
||||||
tuya_color_temp = self.tuya_device.status.get(self.dp_code_temp, 0)
|
tuya_color_temp = self.tuya_device.status.get(self.dp_code_temp, 0)
|
||||||
ha_color_temp = (
|
return (
|
||||||
self.max_mireds
|
self.max_mireds
|
||||||
- self.remap(
|
- self.remap(
|
||||||
tuya_color_temp,
|
tuya_color_temp,
|
||||||
@ -310,7 +310,6 @@ class TuyaHaLight(TuyaHaEntity, LightEntity):
|
|||||||
)
|
)
|
||||||
+ self.min_mireds
|
+ self.min_mireds
|
||||||
)
|
)
|
||||||
return ha_color_temp
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_mireds(self) -> int:
|
def min_mireds(self) -> int:
|
||||||
|
@ -20,14 +20,9 @@ async def async_setup_entry(
|
|||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up tuya scenes."""
|
"""Set up tuya scenes."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
home_manager = hass.data[DOMAIN][entry.entry_id][TUYA_HOME_MANAGER]
|
home_manager = hass.data[DOMAIN][entry.entry_id][TUYA_HOME_MANAGER]
|
||||||
scenes = await hass.async_add_executor_job(home_manager.query_scenes)
|
scenes = await hass.async_add_executor_job(home_manager.query_scenes)
|
||||||
for scene in scenes:
|
async_add_entities(TuyaHAScene(home_manager, scene) for scene in scenes)
|
||||||
entities.append(TuyaHAScene(home_manager, scene))
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class TuyaHAScene(Scene):
|
class TuyaHAScene(Scene):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user