-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04791db
commit 2c0e7ee
Showing
3 changed files
with
68 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""sensor.py""" | ||
|
||
from homeassistant.components.sensor import SensorEntity | ||
from homeassistant.const import ( | ||
UnitOfSpeed, | ||
UnitOfTemperature, | ||
UnitOfPressure, | ||
UnitOfPrecipitationDepth, | ||
) | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
from .const import DOMAIN, LOGGER | ||
|
||
async def async_setup_entry(hass, entry, async_add_entities): | ||
"""Set up Meteo LT sensors based on a config entry.""" | ||
coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"] | ||
nearest_place = hass.data[DOMAIN][entry.entry_id]["nearest_place"] | ||
async_add_entities([MeteoLtCurrentConditionsSensor(coordinator, nearest_place)]) | ||
|
||
class MeteoLtCurrentConditionsSensor(CoordinatorEntity, SensorEntity): | ||
"""Representation of a Meteo.Lt Current Conditions Sensor.""" | ||
|
||
def __init__(self, coordinator, nearest_place): | ||
"""Initialize the sensor.""" | ||
super().__init__(coordinator) | ||
self._name = f"Meteo.Lt {nearest_place.name} - Current Conditions" | ||
self._state = None | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the sensor.""" | ||
return self._name | ||
|
||
@property | ||
def state(self): | ||
"""Return the state of the sensor.""" | ||
return self.coordinator.data.current_conditions().temperature | ||
|
||
@property | ||
def extra_state_attributes(self): | ||
"""Return the state attributes.""" | ||
current_conditions = self.coordinator.data.current_conditions() | ||
LOGGER.debug(f"Current conditions: %s", current_conditions) | ||
|
||
return { | ||
"native_temperature": current_conditions.temperature, | ||
"native_apparent_temperature": current_conditions.apparent_temperature, | ||
"native_wind_speed": current_conditions.wind_speed, | ||
"native_wind_gust_speed": current_conditions.wind_gust_speed, | ||
"wind_bearing": current_conditions.wind_bearing, | ||
"cloud_coverage": current_conditions.cloud_coverage, | ||
"native_pressure": current_conditions.pressure, | ||
"humidity": current_conditions.humidity, | ||
"native_precipitation": current_conditions.precipitation, | ||
"condition": current_conditions.condition, | ||
"native_temperature_unit": UnitOfTemperature.CELSIUS, | ||
"native_wind_speed_unit":UnitOfSpeed.METERS_PER_SECOND, | ||
"native_pressure_unit": UnitOfPressure.HPA, | ||
"native_precipitation_unit": UnitOfPrecipitationDepth.MILLIMETERS, | ||
} |