Clean up Local IP integration (#51126)

This commit is contained in:
Franck Nijhof 2021-05-27 14:04:40 +02:00 committed by GitHub
parent 69e454fd49
commit eb2b60434c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 33 deletions

View file

@ -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()