Don't call update() in constructor (#8276)

pull/8253/merge
Fabian Affolter 2017-07-01 16:14:18 +02:00 committed by Pascal Vizeli
parent 0981956caa
commit e6e0e5263a
1 changed files with 7 additions and 5 deletions

View File

@ -38,7 +38,7 @@ SENSOR_TYPES = {
'pressure': ['Pressure', 'mbar'],
'clouds': ['Cloud coverage', '%'],
'rain': ['Rain', 'mm'],
'snow': ['Snow', 'mm']
'snow': ['Snow', 'mm'],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@ -85,7 +85,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
dev.append(OpenWeatherMapSensor(
name, data, 'forecast', SENSOR_TYPES['temperature'][1]))
add_devices(dev)
add_devices(dev, True)
class OpenWeatherMapSensor(Entity):
@ -100,7 +100,6 @@ class OpenWeatherMapSensor(Entity):
self.type = sensor_type
self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self.update()
@property
def name(self):
@ -130,6 +129,9 @@ class OpenWeatherMapSensor(Entity):
data = self.owa_client.data
fc_data = self.owa_client.fc_data
if data is None or fc_data is None:
return
if self.type == 'weather':
self._state = data.get_detailed_status()
elif self.type == 'temperature':
@ -188,7 +190,7 @@ class WeatherData(object):
except TypeError:
obs = None
if obs is None:
_LOGGER.warning("Failed to fetch data from OpenWeatherMap")
_LOGGER.warning("Failed to fetch data")
return
self.data = obs.get_weather()
@ -199,4 +201,4 @@ class WeatherData(object):
self.latitude, self.longitude)
self.fc_data = obs.get_forecast()
except TypeError:
_LOGGER.warning("Failed to fetch forecast from OpenWeatherMap")
_LOGGER.warning("Failed to fetch forecast")