Little fixes

pull/1644/head
Robbie Trencheny 2016-03-29 21:02:17 -07:00
parent 55daf51108
commit 56e64d477a
1 changed files with 16 additions and 16 deletions

View File

@ -49,7 +49,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
(product_id not in wanted_product_ids): (product_id not in wanted_product_ids):
continue continue
dev.append(UberSensor('time', timeandpriceest, product_id, product)) dev.append(UberSensor('time', timeandpriceest, product_id, product))
if product.get('price_details') is not None: if 'price_details' in product:
dev.append(UberSensor('price', timeandpriceest, dev.append(UberSensor('price', timeandpriceest,
product_id, product)) product_id, product))
add_devices(dev) add_devices(dev)
@ -72,18 +72,18 @@ class UberSensor(Entity):
time_estimate = self._product.get('time_estimate_seconds', 0) time_estimate = self._product.get('time_estimate_seconds', 0)
self._state = int(time_estimate / 60) self._state = int(time_estimate / 60)
elif self._sensortype == "price": elif self._sensortype == "price":
price_details = self._product.get('price_details') if 'price_details' in self._product:
if price_details is not None: price_details = self._product['price_details']
self._unit_of_measurement = price_details.get('currency_code', self._unit_of_measurement = price_details.get('currency_code',
'N/A') 'N/A')
if price_details.get('low_estimate') is None: if 'low_estimate' in price_details:
statekey = 'minimum' statekey = 'minimum'
else: else:
statekey = 'low_estimate' statekey = 'low_estimate'
self._state = int(price_details.get(statekey, 0)) self._state = int(price_details.get(statekey, 0))
else: else:
self._unit_of_measurement = 'N/A' self._unit_of_measurement = 'N/A'
self._state = int(0) self._state = 0
self.update() self.update()
@property @property
@ -104,14 +104,6 @@ class UberSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
price_details = self._product.get('price_details')
if price_details is None:
distance_key = 'Trip distance (in miles)'
distance_val = self._product.get('distance', 'N/A')
else:
distance_key = 'Trip distance (in {}s)'.format(price_details[
'distance_unit'])
distance_val = self._product.get('distance')
time_estimate = self._product.get('time_estimate_seconds', 'N/A') time_estimate = self._product.get('time_estimate_seconds', 'N/A')
params = { params = {
'Product ID': self._product['product_id'], 'Product ID': self._product['product_id'],
@ -120,11 +112,14 @@ class UberSensor(Entity):
'Product description': self._product['description'], 'Product description': self._product['description'],
'Pickup time estimate (in seconds)': time_estimate, 'Pickup time estimate (in seconds)': time_estimate,
'Trip duration (in seconds)': self._product.get('duration', 'N/A'), 'Trip duration (in seconds)': self._product.get('duration', 'N/A'),
distance_key: distance_val,
'Vehicle Capacity': self._product['capacity'] 'Vehicle Capacity': self._product['capacity']
} }
if price_details is not None: if 'price_details' in self._product:
price_details = self._product['price_details']
distance_key = 'Trip distance (in {}s)'.format(price_details[
'distance_unit'])
distance_val = self._product.get('distance')
params['Minimum price'] = price_details['minimum'], params['Minimum price'] = price_details['minimum'],
params['Cost per minute'] = price_details['cost_per_minute'], params['Cost per minute'] = price_details['cost_per_minute'],
params['Distance units'] = price_details['distance_unit'], params['Distance units'] = price_details['distance_unit'],
@ -139,6 +134,11 @@ class UberSensor(Entity):
'N/A'), 'N/A'),
params['Surge multiplier'] = price_details.get('surge_multiplier', params['Surge multiplier'] = price_details.get('surge_multiplier',
'N/A') 'N/A')
else:
distance_key = 'Trip distance (in miles)'
distance_val = self._product.get('distance', 'N/A')
params[distance_key] = distance_val
return params return params
@ -161,7 +161,7 @@ class UberSensor(Entity):
min_price = price_details.get('minimum') min_price = price_details.get('minimum')
self._state = int(price_details.get('low_estimate', min_price)) self._state = int(price_details.get('low_estimate', min_price))
else: else:
self._state = int(0) self._state = 0
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods