Home Assistant Unofficial Reference
2024.12.1
sensor.py
Go to the documentation of this file.
1
"""Sensor platform for local_ip."""
2
3
from
homeassistant.components.network
import
async_get_source_ip
4
from
homeassistant.components.sensor
import
SensorEntity
5
from
homeassistant.config_entries
import
ConfigEntry
6
from
homeassistant.const
import
CONF_NAME
7
from
homeassistant.core
import
HomeAssistant
8
from
homeassistant.helpers.entity_platform
import
AddEntitiesCallback
9
10
from
.const
import
SENSOR
11
12
13
async
def
async_setup_entry
(
14
hass: HomeAssistant,
15
entry: ConfigEntry,
16
async_add_entities: AddEntitiesCallback,
17
) ->
None
:
18
"""Set up the platform from config_entry."""
19
name = entry.data.get(CONF_NAME)
or
"Local IP"
20
async_add_entities
([
IPSensor
(name)],
True
)
21
22
23
class
IPSensor
(
SensorEntity
):
24
"""A simple sensor."""
25
26
_attr_unique_id = SENSOR
27
_attr_translation_key =
"local_ip"
28
29
def
__init__
(self, name: str) ->
None
:
30
"""Initialize the sensor."""
31
self.
_attr_name
_attr_name = name
32
33
async
def
async_update
(self) -> None:
34
"""Fetch new state data for the sensor."""
35
self.
_attr_native_value
_attr_native_value = await
async_get_source_ip
(self.
hass
hass)
homeassistant.components.local_ip.sensor.IPSensor
Definition:
sensor.py:23
homeassistant.components.local_ip.sensor.IPSensor.async_update
None async_update(self)
Definition:
sensor.py:33
homeassistant.components.local_ip.sensor.IPSensor._attr_name
_attr_name
Definition:
sensor.py:31
homeassistant.components.local_ip.sensor.IPSensor._attr_native_value
_attr_native_value
Definition:
sensor.py:35
homeassistant.components.local_ip.sensor.IPSensor.__init__
None __init__(self, str name)
Definition:
sensor.py:29
homeassistant.components.sensor.SensorEntity
Definition:
__init__.py:190
homeassistant.helpers.entity.Entity.hass
hass
Definition:
entity.py:1357
homeassistant.components.local_ip.sensor.async_setup_entry
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition:
sensor.py:17
homeassistant.components.mysensors.sensor.async_add_entities
async_add_entities
Definition:
sensor.py:224
homeassistant.components.network
Definition:
__init__.py:1
homeassistant.components.network.async_get_source_ip
str async_get_source_ip(HomeAssistant hass, str|UndefinedType target_ip=UNDEFINED)
Definition:
__init__.py:40
homeassistant.components.sensor
Definition:
__init__.py:1
homeassistant.config_entries
Definition:
config_entries.py:1
homeassistant.const
Definition:
const.py:1
homeassistant.core
Definition:
core.py:1
homeassistant.helpers.entity_platform
Definition:
entity_platform.py:1
core
homeassistant
components
local_ip
sensor.py
Generated by
1.9.1