mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Activate mypy for rpi_power (#57047)
This commit is contained in:
parent
2f960e558f
commit
08cebb247f
@ -91,6 +91,7 @@ homeassistant.components.recorder.statistics
|
||||
homeassistant.components.remote.*
|
||||
homeassistant.components.renault.*
|
||||
homeassistant.components.rituals_perfume_genie.*
|
||||
homeassistant.components.rpi_power.*
|
||||
homeassistant.components.samsungtv.*
|
||||
homeassistant.components.scene.*
|
||||
homeassistant.components.select.*
|
||||
|
@ -11,6 +11,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -5,7 +5,7 @@ Minimal Kernel needed is 4.14+
|
||||
"""
|
||||
import logging
|
||||
|
||||
from rpi_bad_power import new_under_voltage
|
||||
from rpi_bad_power import UnderVoltage, new_under_voltage
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_PROBLEM,
|
||||
@ -13,6 +13,7 @@ from homeassistant.components.binary_sensor import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -21,8 +22,10 @@ DESCRIPTION_UNDER_VOLTAGE = "Under-voltage was detected. Consider getting a unin
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up rpi_power binary sensor."""
|
||||
under_voltage = await hass.async_add_executor_job(new_under_voltage)
|
||||
async_add_entities([RaspberryChargerBinarySensor(under_voltage)], True)
|
||||
@ -31,43 +34,21 @@ async def async_setup_entry(
|
||||
class RaspberryChargerBinarySensor(BinarySensorEntity):
|
||||
"""Binary sensor representing the rpi power status."""
|
||||
|
||||
def __init__(self, under_voltage):
|
||||
_attr_device_class = DEVICE_CLASS_PROBLEM
|
||||
_attr_icon = "mdi:raspberry-pi"
|
||||
_attr_name = "RPi Power status"
|
||||
_attr_unique_id = "rpi_power" # only one sensor possible
|
||||
|
||||
def __init__(self, under_voltage: UnderVoltage) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self._under_voltage = under_voltage
|
||||
self._is_on = None
|
||||
self._last_is_on = False
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the state."""
|
||||
self._is_on = self._under_voltage.get()
|
||||
if self._is_on != self._last_is_on:
|
||||
if self._is_on:
|
||||
value = self._under_voltage.get()
|
||||
if self._attr_is_on != value:
|
||||
if value:
|
||||
_LOGGER.warning(DESCRIPTION_UNDER_VOLTAGE)
|
||||
else:
|
||||
_LOGGER.info(DESCRIPTION_NORMALIZED)
|
||||
self._last_is_on = self._is_on
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique id of the sensor."""
|
||||
return "rpi_power" # only one sensor possible
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "RPi Power status"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return if there is a problem detected."""
|
||||
return self._is_on
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon of the sensor."""
|
||||
return "mdi:raspberry-pi"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this device."""
|
||||
return DEVICE_CLASS_PROBLEM
|
||||
self._attr_is_on = value
|
||||
|
@ -35,7 +35,7 @@ class RPiPowerFlow(DiscoveryFlowHandler, domain=DOMAIN):
|
||||
self, data: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initialized by onboarding."""
|
||||
has_devices = await self._discovery_function(self.hass)
|
||||
has_devices = await self._discovery_function(self.hass) # type: ignore
|
||||
|
||||
if not has_devices:
|
||||
return self.async_abort(reason="no_devices_found")
|
||||
|
14
mypy.ini
14
mypy.ini
@ -1012,6 +1012,17 @@ no_implicit_optional = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.rpi_power.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
no_implicit_optional = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.samsungtv.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
@ -1695,9 +1706,6 @@ ignore_errors = true
|
||||
[mypy-homeassistant.components.ring.*]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.rpi_power.*]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.ruckus_unleashed.*]
|
||||
ignore_errors = true
|
||||
|
||||
|
@ -106,7 +106,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||
"homeassistant.components.profiler.*",
|
||||
"homeassistant.components.rachio.*",
|
||||
"homeassistant.components.ring.*",
|
||||
"homeassistant.components.rpi_power.*",
|
||||
"homeassistant.components.ruckus_unleashed.*",
|
||||
"homeassistant.components.screenlogic.*",
|
||||
"homeassistant.components.search.*",
|
||||
|
Loading…
x
Reference in New Issue
Block a user