mirror of https://github.com/home-assistant/core
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.remote.*
|
||||||
homeassistant.components.renault.*
|
homeassistant.components.renault.*
|
||||||
homeassistant.components.rituals_perfume_genie.*
|
homeassistant.components.rituals_perfume_genie.*
|
||||||
|
homeassistant.components.rpi_power.*
|
||||||
homeassistant.components.samsungtv.*
|
homeassistant.components.samsungtv.*
|
||||||
homeassistant.components.scene.*
|
homeassistant.components.scene.*
|
||||||
homeassistant.components.select.*
|
homeassistant.components.select.*
|
||||||
|
|
|
@ -11,6 +11,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return True
|
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."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
|
@ -5,7 +5,7 @@ Minimal Kernel needed is 4.14+
|
||||||
"""
|
"""
|
||||||
import logging
|
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 (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_PROBLEM,
|
DEVICE_CLASS_PROBLEM,
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.components.binary_sensor import (
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,8 +22,10 @@ DESCRIPTION_UNDER_VOLTAGE = "Under-voltage was detected. Consider getting a unin
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
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."""
|
"""Set up rpi_power binary sensor."""
|
||||||
under_voltage = await hass.async_add_executor_job(new_under_voltage)
|
under_voltage = await hass.async_add_executor_job(new_under_voltage)
|
||||||
async_add_entities([RaspberryChargerBinarySensor(under_voltage)], True)
|
async_add_entities([RaspberryChargerBinarySensor(under_voltage)], True)
|
||||||
|
@ -31,43 +34,21 @@ async def async_setup_entry(
|
||||||
class RaspberryChargerBinarySensor(BinarySensorEntity):
|
class RaspberryChargerBinarySensor(BinarySensorEntity):
|
||||||
"""Binary sensor representing the rpi power status."""
|
"""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."""
|
"""Initialize the binary sensor."""
|
||||||
self._under_voltage = under_voltage
|
self._under_voltage = under_voltage
|
||||||
self._is_on = None
|
|
||||||
self._last_is_on = False
|
|
||||||
|
|
||||||
def update(self):
|
def update(self) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
self._is_on = self._under_voltage.get()
|
value = self._under_voltage.get()
|
||||||
if self._is_on != self._last_is_on:
|
if self._attr_is_on != value:
|
||||||
if self._is_on:
|
if value:
|
||||||
_LOGGER.warning(DESCRIPTION_UNDER_VOLTAGE)
|
_LOGGER.warning(DESCRIPTION_UNDER_VOLTAGE)
|
||||||
else:
|
else:
|
||||||
_LOGGER.info(DESCRIPTION_NORMALIZED)
|
_LOGGER.info(DESCRIPTION_NORMALIZED)
|
||||||
self._last_is_on = self._is_on
|
self._attr_is_on = value
|
||||||
|
|
||||||
@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
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class RPiPowerFlow(DiscoveryFlowHandler, domain=DOMAIN):
|
||||||
self, data: dict[str, Any] | None = None
|
self, data: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a flow initialized by onboarding."""
|
"""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:
|
if not has_devices:
|
||||||
return self.async_abort(reason="no_devices_found")
|
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_return_any = true
|
||||||
warn_unreachable = 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.*]
|
[mypy-homeassistant.components.samsungtv.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
@ -1695,9 +1706,6 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.ring.*]
|
[mypy-homeassistant.components.ring.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.rpi_power.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.ruckus_unleashed.*]
|
[mypy-homeassistant.components.ruckus_unleashed.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.profiler.*",
|
"homeassistant.components.profiler.*",
|
||||||
"homeassistant.components.rachio.*",
|
"homeassistant.components.rachio.*",
|
||||||
"homeassistant.components.ring.*",
|
"homeassistant.components.ring.*",
|
||||||
"homeassistant.components.rpi_power.*",
|
|
||||||
"homeassistant.components.ruckus_unleashed.*",
|
"homeassistant.components.ruckus_unleashed.*",
|
||||||
"homeassistant.components.screenlogic.*",
|
"homeassistant.components.screenlogic.*",
|
||||||
"homeassistant.components.search.*",
|
"homeassistant.components.search.*",
|
||||||
|
|
Loading…
Reference in New Issue