mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
parent
e7b5c5812c
commit
4fb25cf16d
@ -9,10 +9,10 @@ from datetime import timedelta
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
REQUIREMENTS = ['uber_rides==0.4.1']
|
REQUIREMENTS = ['uber_rides==0.4.1']
|
||||||
|
|
||||||
@ -35,8 +35,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Required(CONF_START_LONGITUDE): cv.longitude,
|
vol.Required(CONF_START_LONGITUDE): cv.longitude,
|
||||||
vol.Optional(CONF_END_LATITUDE): cv.latitude,
|
vol.Optional(CONF_END_LATITUDE): cv.latitude,
|
||||||
vol.Optional(CONF_END_LONGITUDE): cv.longitude,
|
vol.Optional(CONF_END_LONGITUDE): cv.longitude,
|
||||||
vol.Optional(CONF_PRODUCT_IDS):
|
vol.Optional(CONF_PRODUCT_IDS): vol.All(cv.ensure_list, [cv.string]),
|
||||||
vol.All(cv.ensure_list, [cv.string]),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +56,11 @@ 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) and \
|
if product.get('price_details') is not None:
|
||||||
product['price_details']['estimate'] != 'Metered':
|
|
||||||
dev.append(UberSensor(
|
dev.append(UberSensor(
|
||||||
'price', timeandpriceest, product_id, product))
|
'price', timeandpriceest, product_id, product))
|
||||||
add_devices(dev)
|
|
||||||
|
add_devices(dev, True)
|
||||||
|
|
||||||
|
|
||||||
class UberSensor(Entity):
|
class UberSensor(Entity):
|
||||||
@ -73,8 +72,8 @@ class UberSensor(Entity):
|
|||||||
self._product_id = product_id
|
self._product_id = product_id
|
||||||
self._product = product
|
self._product = product
|
||||||
self._sensortype = sensorType
|
self._sensortype = sensorType
|
||||||
self._name = '{} {}'.format(self._product['display_name'],
|
self._name = '{} {}'.format(
|
||||||
self._sensortype)
|
self._product['display_name'], self._sensortype)
|
||||||
if self._sensortype == 'time':
|
if self._sensortype == 'time':
|
||||||
self._unit_of_measurement = 'min'
|
self._unit_of_measurement = 'min'
|
||||||
time_estimate = self._product.get('time_estimate_seconds', 0)
|
time_estimate = self._product.get('time_estimate_seconds', 0)
|
||||||
@ -90,7 +89,6 @@ class UberSensor(Entity):
|
|||||||
self._state = int(price_details.get(statekey, 0))
|
self._state = int(price_details.get(statekey, 0))
|
||||||
else:
|
else:
|
||||||
self._state = 0
|
self._state = 0
|
||||||
self.update()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -214,8 +212,8 @@ class UberEstimate(object):
|
|||||||
if product.get('price_details') is None:
|
if product.get('price_details') is None:
|
||||||
price_details = {}
|
price_details = {}
|
||||||
price_details['estimate'] = price.get('estimate', '0')
|
price_details['estimate'] = price.get('estimate', '0')
|
||||||
price_details['high_estimate'] = price.get('high_estimate',
|
price_details['high_estimate'] = price.get(
|
||||||
'0')
|
'high_estimate', '0')
|
||||||
price_details['low_estimate'] = price.get('low_estimate', '0')
|
price_details['low_estimate'] = price.get('low_estimate', '0')
|
||||||
price_details['currency_code'] = price.get('currency_code')
|
price_details['currency_code'] = price.get('currency_code')
|
||||||
surge_multiplier = price.get('surge_multiplier', '0')
|
surge_multiplier = price.get('surge_multiplier', '0')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user