From 4a3048b370cca4aa6aae88d9114587ba50cba9cc Mon Sep 17 00:00:00 2001 From: Johan Bloemberg Date: Sat, 13 May 2017 01:04:30 +0200 Subject: [PATCH] Initialize sun with correct values. (#7559) * Initialize sun with unknown values. Initial values should be `unknown` instead of `0`. Otherwise on HA restart the value of `0` is pushed to metrics databases (graphite/influx/recorder). * Update sun position before emitting initial update * Simplify based on armills comment. * Use provided time for calculation. --- homeassistant/components/sun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/sun.py b/homeassistant/components/sun.py index 8254b4b2f0e..9d3d82bd8fc 100644 --- a/homeassistant/components/sun.py +++ b/homeassistant/components/sun.py @@ -62,7 +62,7 @@ class Sun(Entity): self._state = self.next_rising = self.next_setting = None self.next_dawn = self.next_dusk = None self.next_midnight = self.next_noon = None - self.solar_elevation = self.solar_azimuth = 0 + self.solar_elevation = self.solar_azimuth = None async_track_utc_time_change(hass, self.timer_update, second=30) @@ -124,6 +124,7 @@ class Sun(Entity): @callback def point_in_time_listener(self, now): """Run when the state of the sun has changed.""" + self.update_sun_position(now) self.update_as_of(now) self.hass.async_add_job(self.async_update_ha_state())