Code cleanup fibaro switch and binary sensor (#73386)

This commit is contained in:
rappenze 2022-06-20 15:46:28 +02:00 committed by GitHub
parent 670bf0641a
commit 483406dea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -1,6 +1,8 @@
"""Support for Fibaro binary sensors."""
from __future__ import annotations
from typing import Any
from homeassistant.components.binary_sensor import (
ENTITY_ID_FORMAT,
BinarySensorDeviceClass,
@ -49,7 +51,7 @@ async def async_setup_entry(
class FibaroBinarySensor(FibaroDevice, BinarySensorEntity):
"""Representation of a Fibaro Binary Sensor."""
def __init__(self, fibaro_device):
def __init__(self, fibaro_device: Any) -> None:
"""Initialize the binary_sensor."""
super().__init__(fibaro_device)
self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
@ -62,6 +64,6 @@ class FibaroBinarySensor(FibaroDevice, BinarySensorEntity):
self._attr_device_class = SENSOR_TYPES[stype][2]
self._attr_icon = SENSOR_TYPES[stype][1]
def update(self):
def update(self) -> None:
"""Get the latest data and update the state."""
self._attr_is_on = self.current_binary_state

View File

@ -1,6 +1,8 @@
"""Support for Fibaro switches."""
from __future__ import annotations
from typing import Any
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
@ -31,27 +33,21 @@ async def async_setup_entry(
class FibaroSwitch(FibaroDevice, SwitchEntity):
"""Representation of a Fibaro Switch."""
def __init__(self, fibaro_device):
def __init__(self, fibaro_device: Any) -> None:
"""Initialize the Fibaro device."""
self._state = False
super().__init__(fibaro_device)
self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn device on."""
self.call_turn_on()
self._state = True
self._attr_is_on = True
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn device off."""
self.call_turn_off()
self._state = False
self._attr_is_on = False
@property
def is_on(self):
"""Return true if device is on."""
return self._state
def update(self):
def update(self) -> None:
"""Update device state."""
self._state = self.current_binary_state
self._attr_is_on = self.current_binary_state