-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SensorEntityDescription in sensor
- Loading branch information
Showing
2 changed files
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
"""Sensor platform for integration_blueprint.""" | ||
from homeassistant.components.sensor import SensorEntity | ||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription | ||
|
||
from .const import DEFAULT_NAME, DOMAIN, ICON, SENSOR | ||
from .const import DOMAIN | ||
from .coordinator import BlueprintDataUpdateCoordinator | ||
from .entity import IntegrationBlueprintEntity | ||
|
||
|
||
ENTITY_DESCRIPTIONS = ( | ||
SensorEntityDescription( | ||
key="integration_blueprint", | ||
name="Integration Sensor", | ||
icon="mdi:format-quote-close", | ||
), | ||
) | ||
|
||
|
||
async def async_setup_entry(hass, entry, async_add_devices): | ||
"""Setup sensor platform.""" | ||
coordinator = hass.data[DOMAIN][entry.entry_id] | ||
async_add_devices([IntegrationBlueprintSensor(coordinator, entry)]) | ||
async_add_devices( | ||
IntegrationBlueprintSensor( | ||
coordinator=coordinator, | ||
entity_description=entity_description, | ||
) | ||
for entity_description in ENTITY_DESCRIPTIONS | ||
) | ||
|
||
|
||
class IntegrationBlueprintSensor(IntegrationBlueprintEntity, SensorEntity): | ||
"""integration_blueprint Sensor class.""" | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the sensor.""" | ||
return f"{DEFAULT_NAME}_{SENSOR}" | ||
def __init__( | ||
self, | ||
coordinator: BlueprintDataUpdateCoordinator, | ||
entity_description: SensorEntityDescription, | ||
) -> None: | ||
super().__init__(coordinator) | ||
self.entity_description = entity_description | ||
|
||
@property | ||
def native_value(self): | ||
"""Return the native value of the sensor.""" | ||
return self.coordinator.data.get("body") | ||
|
||
@property | ||
def icon(self): | ||
"""Return the icon of the sensor.""" | ||
return ICON |