diff --git a/.strict-typing b/.strict-typing index 00bc3447d22..3d777a11acf 100644 --- a/.strict-typing +++ b/.strict-typing @@ -41,6 +41,7 @@ homeassistant.components.integration.* homeassistant.components.knx.* homeassistant.components.kraken.* homeassistant.components.light.* +homeassistant.components.local_ip.* homeassistant.components.lock.* homeassistant.components.mailbox.* homeassistant.components.media_player.* diff --git a/homeassistant/components/local_ip/__init__.py b/homeassistant/components/local_ip/__init__.py index c4e8c541e4a..e97e5da7d49 100644 --- a/homeassistant/components/local_ip/__init__.py +++ b/homeassistant/components/local_ip/__init__.py @@ -8,12 +8,12 @@ from .const import DOMAIN, PLATFORMS CONFIG_SCHEMA = cv.deprecated(DOMAIN) -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up local_ip from a config entry.""" hass.config_entries.async_setup_platforms(entry, PLATFORMS) 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) diff --git a/homeassistant/components/local_ip/config_flow.py b/homeassistant/components/local_ip/config_flow.py index 2bc994c4dca..27bd5340d40 100644 --- a/homeassistant/components/local_ip/config_flow.py +++ b/homeassistant/components/local_ip/config_flow.py @@ -1,18 +1,23 @@ """Config flow for local_ip.""" +from __future__ import annotations -from homeassistant import config_entries +from typing import Any + +from homeassistant.config_entries import ConfigFlow +from homeassistant.data_entry_flow import FlowResult from .const import DOMAIN -class SimpleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): +class SimpleConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for local_ip.""" VERSION = 1 - async def async_step_user(self, user_input=None): + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle the initial step.""" - if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") diff --git a/homeassistant/components/local_ip/sensor.py b/homeassistant/components/local_ip/sensor.py index 1d2cce72105..c7bc53caa69 100644 --- a/homeassistant/components/local_ip/sensor.py +++ b/homeassistant/components/local_ip/sensor.py @@ -1,46 +1,35 @@ """Sensor platform for local_ip.""" from homeassistant.components.sensor import SensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util import get_local_ip from .const import DOMAIN, SENSOR -async def async_setup_entry(hass, config_entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: """Set up the platform from config_entry.""" - name = config_entry.data.get(CONF_NAME) or DOMAIN + name = entry.data.get(CONF_NAME) or DOMAIN async_add_entities([IPSensor(name)], True) class IPSensor(SensorEntity): """A simple sensor.""" - def __init__(self, name): + _attr_unique_id = SENSOR + _attr_icon = "mdi:ip" + + def __init__(self, name: str) -> None: """Initialize the sensor.""" - self._state = None - self._name = name + self._attr_name = name - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def unique_id(self): - """Return the unique id of the sensor.""" - return SENSOR - - @property - def state(self): - """Return the state of the sensor.""" - return self._state - - @property - def icon(self): - """Return the icon of the sensor.""" - return "mdi:ip" - - def update(self): + def update(self) -> None: """Fetch new state data for the sensor.""" - self._state = get_local_ip() + self._attr_state = get_local_ip() diff --git a/mypy.ini b/mypy.ini index c65f28336ff..231f7f40384 100644 --- a/mypy.ini +++ b/mypy.ini @@ -462,6 +462,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.local_ip.*] +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.lock.*] check_untyped_defs = true disallow_incomplete_defs = true