Skip to content

Commit

Permalink
Merge pull request #411 from dvd-dev/outside-temp
Browse files Browse the repository at this point in the history
Ajout de la température extérieure au gateway
  • Loading branch information
valleedelisle authored Apr 17, 2024
2 parents 2b3c30e + 3b80a2a commit ed538d3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ rewrite it. Hilo is now pushing device readings via websocket from SignalR.
- Generates energy meters and sensors
- Sensor for Hilo Events (challenges)
- Sensor for Hilo Gateway
- **NEW**: Now configuration is done via the UI
- **NEW**: Updates are now closer to realtime
- Now configuration is done via the UI
- Updates are now closer to realtime
- **NEW**: Authentication directly on Hilo's website
- **NEW**: Outdoor weather sensor with changing icon like in the Hilo App

### To Do:
- Add functionalities for other devices
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ J'ai décidé de déplacer l'intégration ici, car la dernière mise à jour de
- Générer les "sensor" de puissance et d'énergie consommée.
- Sensor pour les Défis.
- Sensor pour la passerelle Hilo
- **NOUVEAU**: Configuration est maintenant faite via l'interface utilisateur
- **NOUVEAU**: Mise à jour des lectures plus près du temps réel.
- Configuration est maintenant faite via l'interface utilisateur
- Mise à jour des lectures plus près du temps réel.
- **NOUVEAU**: Authentification via le site de Hilo
- **NOUVEAU**: Capteur pour la météo extérieure avec icône changeante comme dans l'app Hilo

### À faire:
- Ajouter la fonctionnalité pour d'autres appareils.
Expand Down Expand Up @@ -79,7 +81,7 @@ Dans le coin inférieur droit, cliquer sur le bouton '+ AJOUTER UNE INTÉGRATION

![Ajout intégration](https://github.com/dvd-dev/hilo/assets/108159253/e0529aca-9b13-40e0-9be4-29e347b980ab)

Si l'intégration est correctement installée, vous devriez pouvoir trouver "Hilo" dans la list. Il est possible d'avoir besoin de vider la mémoire cache de votre navigateur pour que l'intégration s'affiche.
Si l'intégration est correctement installée, vous devriez pouvoir trouver "Hilo" dans la liste. Il est possible d'avoir besoin de vider la mémoire cache de votre navigateur pour que l'intégration s'affiche.

![Recherche intégration](https://github.com/dvd-dev/hilo/assets/108159253/7003a402-9369-4063-ac02-709bd0294e42)

Expand Down
16 changes: 16 additions & 0 deletions custom_components/hilo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@

TARIFF_LIST = ["high", "medium", "low"]

WEATHER_CONDITIONS = {
"Unknown": "mdi:weather-sunny-alert",
"Blowing Snow": "mdi:weather-snowy-heavy",
"Clear": "mdi:weather-sunny",
"Cloudy": "mdi:weather-cloudy",
"Fair": "mdi:weather-partly-cloudy",
"Foggy": "mdi:weather-fog",
"Hail Sleet": "mdi:weather-hail",
"Mostly Cloudy": "mdi:weather-partly-cloudy",
"Rain": "mdi:weather-rainy",
"Rain Snow": "mdi:weather-snowy-rainy",
"Snow": "mdi:weather-snowy",
"Thunder": "mdi:weather-lightning",
"Windy": "mdi:weather-windy",
}

# Class lists
LIGHT_CLASSES = ["LightDimmer", "WhiteBulb", "ColorBulb", "LightSwitch"]
HILO_SENSOR_CLASSES = [
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hilo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"documentation": "https://github.com/dvd-dev/hilo",
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/dvd-dev/hilo/issues",
"requirements": ["python-hilo>=2024.3.1"],
"version": "2024.4.1"
"requirements": ["python-hilo>=2024.4.1"],
"version": "2024.4.2"
}
70 changes: 70 additions & 0 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CURRENCY_DOLLAR,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
STATE_UNKNOWN,
Platform,
UnitOfEnergy,
UnitOfPower,
Expand Down Expand Up @@ -56,6 +57,7 @@
NOTIFICATION_SCAN_INTERVAL,
REWARD_SCAN_INTERVAL,
TARIFF_LIST,
WEATHER_CONDITIONS,
)
from .managers import EnergyManager, UtilityManager

Expand Down Expand Up @@ -99,6 +101,9 @@ def generate_entities_from_device(device, hilo, scan_interval):
entities.append(
HiloNotificationSensor(hilo, device, scan_interval),
)
entities.append(
HiloOutdoorTempSensor(hilo, device, scan_interval),
)
if device.has_attribute("battery"):
entities.append(BatterySensor(hilo, device))
if device.has_attribute("co2"):
Expand Down Expand Up @@ -835,3 +840,68 @@ async def async_added_to_hass(self):

async def async_update(self):
return


class HiloOutdoorTempSensor(HiloEntity, SensorEntity):
"""Hilo outdoor temperature sensor.
Its state will be the current outdoor weather as reported by the Hilo App
"""

_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_state_class = SensorStateClass.MEASUREMENT

def __init__(self, hilo, device, scan_interval):
self._attr_name = "Outdoor Weather Hilo"
super().__init__(hilo, name=self._attr_name, device=device)
self._attr_unique_id = (
f"{slugify(device.identifier)}-{slugify(self._attr_name)}"
)
LOG.debug(f"Setting up OutdoorWeatherSensor entity: {self._attr_name}")
self.scan_interval = timedelta(seconds=EVENT_SCAN_INTERVAL_REDUCTION)
self._state = STATE_UNKNOWN
self._weather = {}
self.async_update = Throttle(self.scan_interval)(self._async_update)

@property
def state(self):
try:
return int(self._state)
except ValueError:
return STATE_UNKNOWN

@property
def icon(self):
condition = self._weather.get("condition", "").lower()
LOG.warning(f"Current condition: {condition}")
if not condition:
return "mdi:lan-disconnect"
return WEATHER_CONDITIONS.get(self._weather.get("condition", "Unknown"))

@property
def should_poll(self):
return True

@property
def extra_state_attributes(self):
LOG.debug(f"Adding weather {self._weather}")
return {
key: self._weather[key]
for key in self._weather
if key not in ["temperature", "icon"]
}

# async def async_added_to_hass(self):
# """Handle entity about to be added to hass event."""
# await super().async_added_to_hass()
# last_state = await self.async_get_last_state()
# if last_state:
# self._last_update = dt_util.utcnow()
# self._state = last_state.state

async def _async_update(self):
self._weather = {}
self._weather = await self._hilo._api.get_weather(
self._hilo.devices.location_id
)
self._state = self._weather.get("temperature")

0 comments on commit ed538d3

Please sign in to comment.