Add local_ip unique_id & icon and single_instance_allowed (#33483)

* Add config flow + sensor unique_id & icon to local_ip

* single_instance_allowed

* Fix test

* Martin's review

* Name deprecated
This commit is contained in:
Quentame 2020-04-09 16:06:01 +02:00 committed by GitHub
parent dd7fbef948
commit 45b28b8b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 37 deletions

View file

@ -1,20 +1,22 @@
"""Sensor platform for local_ip."""
from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_NAME
from homeassistant.helpers.entity import Entity
from homeassistant.util import get_local_ip
from .const import DOMAIN, SENSOR
async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entities):
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the platform from config_entry."""
name = config_entry.data["name"]
name = config_entry.data.get(CONF_NAME) or DOMAIN
async_add_entities([IPSensor(name)], True)
class IPSensor(Entity):
"""A simple sensor."""
def __init__(self, name: str):
def __init__(self, name):
"""Initialize the sensor."""
self._state = None
self._name = name
@ -24,11 +26,21 @@ class IPSensor(Entity):
"""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):
"""Fetch new state data for the sensor."""
self._state = get_local_ip()