Enforce entity attribute types

This commit is contained in:
Paulus Schoutsen 2016-01-17 17:50:20 -08:00
parent 06b4fcc2cf
commit a9c6f8c1d9
12 changed files with 36 additions and 35 deletions

View file

@ -17,24 +17,24 @@ REQUIREMENTS = ['blockchain==1.1.2']
_LOGGER = logging.getLogger(__name__)
OPTION_TYPES = {
'wallet': ['Wallet balance', 'BTC'],
'exchangerate': ['Exchange rate (1 BTC)', ''],
'exchangerate': ['Exchange rate (1 BTC)', None],
'trade_volume_btc': ['Trade volume', 'BTC'],
'miners_revenue_usd': ['Miners revenue', 'USD'],
'btc_mined': ['Mined', 'BTC'],
'trade_volume_usd': ['Trade volume', 'USD'],
'difficulty': ['Difficulty', ''],
'difficulty': ['Difficulty', None],
'minutes_between_blocks': ['Time between Blocks', 'min'],
'number_of_transactions': ['No. of Transactions', ''],
'number_of_transactions': ['No. of Transactions', None],
'hash_rate': ['Hash rate', 'PH/s'],
'timestamp': ['Timestamp', ''],
'mined_blocks': ['Minded Blocks', ''],
'blocks_size': ['Block size', ''],
'timestamp': ['Timestamp', None],
'mined_blocks': ['Minded Blocks', None],
'blocks_size': ['Block size', None],
'total_fees_btc': ['Total fees', 'BTC'],
'total_btc_sent': ['Total sent', 'BTC'],
'estimated_btc_sent': ['Estimated sent', 'BTC'],
'total_btc': ['Total', 'BTC'],
'total_blocks': ['Total Blocks', ''],
'next_retarget': ['Next retarget', ''],
'total_blocks': ['Total Blocks', None],
'next_retarget': ['Next retarget', None],
'estimated_transaction_volume_usd': ['Est. Transaction volume', 'USD'],
'miners_revenue_btc': ['Miners revenue', 'BTC'],
'market_price_usd': ['Market price', 'USD']

View file

@ -20,7 +20,7 @@ REQUIREMENTS = ['http://github.com/mala-zaba/Adafruit_Python_DHT/archive/'
_LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = {
'temperature': ['Temperature', ''],
'temperature': ['Temperature', None],
'humidity': ['Humidity', '%']
}
# Return cached results if last scan was less then this time ago

View file

@ -36,7 +36,7 @@ DEPENDENCIES = ['ecobee']
SENSOR_TYPES = {
'temperature': ['Temperature', TEMP_FAHRENHEIT],
'humidity': ['Humidity', '%'],
'occupancy': ['Occupancy', '']
'occupancy': ['Occupancy', None]
}
_LOGGER = logging.getLogger(__name__)

View file

@ -16,8 +16,8 @@ _LOGGER = logging.getLogger(__name__)
_RESOURCE = 'https://engage.efergy.com/mobile_proxy/'
SENSOR_TYPES = {
'instant_readings': ['Energy Usage', 'kW'],
'budget': ['Energy Budget', ''],
'cost': ['Energy Cost', ''],
'budget': ['Energy Budget', None],
'cost': ['Energy Cost', None],
}

View file

@ -19,13 +19,13 @@ _LOGGER = logging.getLogger(__name__)
# Sensor types are defined like so:
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
SENSOR_TYPES = {
'summary': ['Summary', '', '', '', '', ''],
'icon': ['Icon', '', '', '', '', ''],
'summary': ['Summary', None, None, None, None, None],
'icon': ['Icon', None, None, None, None, None],
'nearest_storm_distance': ['Nearest Storm Distance',
'km', 'm', 'km', 'km', 'm'],
'nearest_storm_bearing': ['Nearest Storm Bearing',
'°', '°', '°', '°', '°'],
'precip_type': ['Precip', '', '', '', '', ''],
'precip_type': ['Precip', None, None, None, None, None],
'precip_intensity': ['Precip Intensity', 'mm', 'in', 'mm', 'mm', 'mm'],
'precip_probability': ['Precip Probability', '%', '%', '%', '%', '%'],
'temperature': ['Temperature', '°C', '°F', '°C', '°C', '°C'],

View file

@ -31,11 +31,11 @@ SENSOR_TYPES = {
'swap_use_percent': ['Swap Use', '%'],
'swap_use': ['Swap Use', 'GiB'],
'swap_free': ['Swap Free', 'GiB'],
'processor_load': ['CPU Load', ''],
'process_running': ['Running', ''],
'process_total': ['Total', ''],
'process_thread': ['Thread', ''],
'process_sleeping': ['Sleeping', '']
'processor_load': ['CPU Load', None],
'process_running': ['Running', None],
'process_total': ['Total', None],
'process_thread': ['Thread', None],
'process_sleeping': ['Sleeping', None]
}
_LOGGER = logging.getLogger(__name__)

View file

@ -16,8 +16,8 @@ from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['pyowm==2.3.0']
_LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = {
'weather': ['Condition', ''],
'temperature': ['Temperature', ''],
'weather': ['Condition', None],
'temperature': ['Temperature', None],
'wind_speed': ['Wind speed', 'm/s'],
'humidity': ['Humidity', '%'],
'pressure': ['Pressure', 'mbar'],
@ -71,7 +71,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
pass
if forecast == 1:
SENSOR_TYPES['forecast'] = ['Forecast', '']
SENSOR_TYPES['forecast'] = ['Forecast', None]
dev.append(OpenWeatherMapSensor(data, 'forecast', unit))
add_devices(dev)

View file

@ -17,7 +17,7 @@ REQUIREMENTS = ['https://github.com/jamespcole/home-assistant-nzb-clients/'
'#python-sabnzbd==0.1']
SENSOR_TYPES = {
'current_status': ['Status', ''],
'current_status': ['Status', None],
'speed': ['Speed', 'MB/s'],
'queue_size': ['Queue', 'MB'],
'queue_remaining': ['Left', 'MB'],

View file

@ -15,7 +15,7 @@ from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['transmissionrpc==0.11']
SENSOR_TYPES = {
'current_status': ['Status', ''],
'current_status': ['Status', None],
'download_speed': ['Down Speed', 'MB/s'],
'upload_speed': ['Up Speed', 'MB/s']
}

View file

@ -67,7 +67,7 @@ class VerisureThermometer(Entity):
return TEMP_CELCIUS # can verisure report in fahrenheit?
def update(self):
''' update sensor '''
""" update sensor """
verisure.update_climate()
@ -96,5 +96,5 @@ class VerisureHygrometer(Entity):
return "%"
def update(self):
''' update sensor '''
""" update sensor """
verisure.update_climate()

View file

@ -21,7 +21,7 @@ REQUIREMENTS = ['xmltodict']
# Sensor types are defined like so:
SENSOR_TYPES = {
'symbol': ['Symbol', ''],
'symbol': ['Symbol', None],
'precipitation': ['Condition', 'mm'],
'temperature': ['Temperature', '°C'],
'windSpeed': ['Wind speed', 'm/s'],

View file

@ -101,17 +101,18 @@ class Entity(object):
state = str(self.state)
attr = self.state_attributes or {}
if ATTR_FRIENDLY_NAME not in attr and self.name:
attr[ATTR_FRIENDLY_NAME] = self.name
if ATTR_FRIENDLY_NAME not in attr and self.name is not None:
attr[ATTR_FRIENDLY_NAME] = str(self.name)
if ATTR_UNIT_OF_MEASUREMENT not in attr and self.unit_of_measurement:
attr[ATTR_UNIT_OF_MEASUREMENT] = self.unit_of_measurement
if ATTR_UNIT_OF_MEASUREMENT not in attr and \
self.unit_of_measurement is not None:
attr[ATTR_UNIT_OF_MEASUREMENT] = str(self.unit_of_measurement)
if ATTR_ICON not in attr and self.icon:
attr[ATTR_ICON] = self.icon
if ATTR_ICON not in attr and self.icon is not None:
attr[ATTR_ICON] = str(self.icon)
if self.hidden:
attr[ATTR_HIDDEN] = self.hidden
attr[ATTR_HIDDEN] = bool(self.hidden)
# overwrite properties that have been set in the config file
attr.update(_OVERWRITE.get(self.entity_id, {}))