remove the use of unnecessary dictionary.

This commit is contained in:
nkgilley@gmail.com 2015-12-02 17:42:53 -05:00
parent 502184812d
commit 7985468aba

View File

@ -49,30 +49,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if discovery_info is None: if discovery_info is None:
return return
data = ecobee.NETWORK data = ecobee.NETWORK
sensor_list = list() dev = list()
for index in range(len(data.ecobee.thermostats)): for index in range(len(data.ecobee.thermostats)):
sensors = dict()
for sensor in data.ecobee.get_remote_sensors(index): for sensor in data.ecobee.get_remote_sensors(index):
sensor_info = dict()
for item in sensor['capability']: for item in sensor['capability']:
if item['type'] == 'temperature': if item['type'] == 'temperature':
sensor_info['temp'] = float(item['value']) / 10 dev.append(
EcobeeSensor(sensor['name'], 'temperature', index))
elif item['type'] == 'humidity': elif item['type'] == 'humidity':
sensor_info['humidity'] = item['value'] dev.append(
EcobeeSensor(sensor['name'], 'humidity', index))
elif item['type'] == 'occupancy': elif item['type'] == 'occupancy':
sensor_info['occupancy'] = item['value'] dev.append(
sensors[sensor['name']] = sensor_info EcobeeSensor(sensor['name'], 'occupancy', index))
sensor_list.append(sensors)
dev = list()
for index in range(len(sensor_list)):
for name, data in sensor_list[index].items():
if 'temp' in data:
dev.append(EcobeeSensor(name, 'temperature', index))
if 'humidity' in data:
dev.append(EcobeeSensor(name, 'humidity', index))
if 'occupancy' in data:
dev.append(EcobeeSensor(name, 'occupancy', index))
add_devices(dev) add_devices(dev)
@ -103,20 +92,22 @@ class EcobeeSensor(Entity):
return self._unit_of_measurement return self._unit_of_measurement
def update(self): def update(self):
ecobee.NETWORK.update()
data = ecobee.NETWORK data = ecobee.NETWORK
data.update()
for sensor in data.ecobee.get_remote_sensors(self.index): for sensor in data.ecobee.get_remote_sensors(self.index):
sensor_info = dict()
for item in sensor['capability']: for item in sensor['capability']:
if item['type'] == 'temperature': if (
sensor_info['temp'] = float(item['value']) / 10 item['type'] == self.type and
elif item['type'] == 'humidity': self.type == 'temperature' and
sensor_info['humidity'] = item['value'] self.sensor_name == sensor['name']):
elif item['type'] == 'occupancy': self._state = float(item['value']) / 10
sensor_info['occupancy'] = item['value'] elif (
if self.type == 'temperature': item['type'] == self.type and
self._state = sensor_info['temp'] self.type == 'humidity' and
elif self.type == 'humidity': self.sensor_name == sensor['name']):
self._state = sensor_info['humidity'] self._state = item['value']
elif self.type == 'occupancy': elif (
self._state = sensor_info['occupancy'] item['type'] == self.type and
self.type == 'occupancy' and
self.sensor_name == sensor['name']):
self._state = item['value']