mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
parent
4b124e4c25
commit
8861909ea4
@ -10,7 +10,8 @@ from homeassistant.helpers.typing import HomeAssistantType
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
from aioesphomeapi import SensorInfo, SensorState # noqa
|
from aioesphomeapi import ( # noqa
|
||||||
|
SensorInfo, SensorState, TextSensorInfo, TextSensorState)
|
||||||
|
|
||||||
DEPENDENCIES = ['esphome']
|
DEPENDENCIES = ['esphome']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -20,7 +21,8 @@ async def async_setup_entry(hass: HomeAssistantType,
|
|||||||
entry: ConfigEntry, async_add_entities) -> None:
|
entry: ConfigEntry, async_add_entities) -> None:
|
||||||
"""Set up esphome sensors based on a config entry."""
|
"""Set up esphome sensors based on a config entry."""
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
from aioesphomeapi import SensorInfo, SensorState # noqa
|
from aioesphomeapi import ( # noqa
|
||||||
|
SensorInfo, SensorState, TextSensorInfo, TextSensorState)
|
||||||
|
|
||||||
await platform_async_setup_entry(
|
await platform_async_setup_entry(
|
||||||
hass, entry, async_add_entities,
|
hass, entry, async_add_entities,
|
||||||
@ -28,6 +30,12 @@ async def async_setup_entry(hass: HomeAssistantType,
|
|||||||
info_type=SensorInfo, entity_type=EsphomeSensor,
|
info_type=SensorInfo, entity_type=EsphomeSensor,
|
||||||
state_type=SensorState
|
state_type=SensorState
|
||||||
)
|
)
|
||||||
|
await platform_async_setup_entry(
|
||||||
|
hass, entry, async_add_entities,
|
||||||
|
component_key='text_sensor',
|
||||||
|
info_type=TextSensorInfo, entity_type=EsphomeTextSensor,
|
||||||
|
state_type=TextSensorState
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EsphomeSensor(EsphomeEntity):
|
class EsphomeSensor(EsphomeEntity):
|
||||||
@ -60,3 +68,27 @@ class EsphomeSensor(EsphomeEntity):
|
|||||||
def unit_of_measurement(self) -> str:
|
def unit_of_measurement(self) -> str:
|
||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._static_info.unit_of_measurement
|
return self._static_info.unit_of_measurement
|
||||||
|
|
||||||
|
|
||||||
|
class EsphomeTextSensor(EsphomeEntity):
|
||||||
|
"""A text sensor implementation for ESPHome."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _static_info(self) -> 'TextSensorInfo':
|
||||||
|
return super()._static_info
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _state(self) -> Optional['TextSensorState']:
|
||||||
|
return super()._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self) -> str:
|
||||||
|
"""Return the icon."""
|
||||||
|
return self._static_info.icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self) -> Optional[str]:
|
||||||
|
"""Return the state of the entity."""
|
||||||
|
if self._state is None:
|
||||||
|
return None
|
||||||
|
return self._state.state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user