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