Improve type hints in home_connect (#77587)

This commit is contained in:
epenet 2022-08-31 22:16:21 +02:00 committed by GitHub
parent 448f4ee755
commit 152022aef3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 11 deletions

View file

@ -68,7 +68,7 @@ class HomeConnectBinarySensor(HomeConnectEntity, BinarySensorEntity):
return bool(self._state) return bool(self._state)
@property @property
def available(self): def available(self) -> bool:
"""Return true if the binary sensor is available.""" """Return true if the binary sensor is available."""
return self._state is not None return self._state is not None

View file

@ -93,7 +93,7 @@ class HomeConnectLight(HomeConnectEntity, LightEntity):
"""Return the color property.""" """Return the color property."""
return self._hs_color return self._hs_color
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Switch the light on, change brightness, change color.""" """Switch the light on, change brightness, change color."""
if self._ambient: if self._ambient:
_LOGGER.debug("Switching ambient light on for: %s", self.name) _LOGGER.debug("Switching ambient light on for: %s", self.name)
@ -121,7 +121,9 @@ class HomeConnectLight(HomeConnectEntity, LightEntity):
hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color) hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color)
if hs_color is not None: if hs_color is not None:
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness) rgb = color_util.color_hsv_to_RGB(
hs_color[0], hs_color[1], brightness
)
hex_val = color_util.color_rgb_to_hex(rgb[0], rgb[1], rgb[2]) hex_val = color_util.color_rgb_to_hex(rgb[0], rgb[1], rgb[2])
try: try:
await self.hass.async_add_executor_job( await self.hass.async_add_executor_job(
@ -165,7 +167,7 @@ class HomeConnectLight(HomeConnectEntity, LightEntity):
_LOGGER.error("Error while trying to turn off light: %s", err) _LOGGER.error("Error while trying to turn off light: %s", err)
self.async_entity_update() self.async_entity_update()
async def async_update(self): async def async_update(self) -> None:
"""Update the light's status.""" """Update the light's status."""
if self.device.appliance.status.get(self._key, {}).get(ATTR_VALUE) is True: if self.device.appliance.status.get(self._key, {}).get(ATTR_VALUE) is True:
self._state = True self._state = True

View file

@ -49,11 +49,11 @@ class HomeConnectSensor(HomeConnectEntity, SensorEntity):
@property @property
def native_value(self): def native_value(self):
"""Return true if the binary sensor is on.""" """Return sensor value."""
return self._state return self._state
@property @property
def available(self): def available(self) -> bool:
"""Return true if the sensor is available.""" """Return true if the sensor is available."""
return self._state is not None return self._state is not None

View file

@ -60,11 +60,6 @@ class HomeConnectProgramSwitch(HomeConnectEntity, SwitchEntity):
"""Return true if the switch is on.""" """Return true if the switch is on."""
return bool(self._state) return bool(self._state)
@property
def available(self):
"""Return true if the entity is available."""
return True
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Start the program.""" """Start the program."""
_LOGGER.debug("Tried to turn on program %s", self.program_name) _LOGGER.debug("Tried to turn on program %s", self.program_name)