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__) _LOGGER = logging.getLogger(__name__)
OPTION_TYPES = { OPTION_TYPES = {
'wallet': ['Wallet balance', 'BTC'], 'wallet': ['Wallet balance', 'BTC'],
'exchangerate': ['Exchange rate (1 BTC)', ''], 'exchangerate': ['Exchange rate (1 BTC)', None],
'trade_volume_btc': ['Trade volume', 'BTC'], 'trade_volume_btc': ['Trade volume', 'BTC'],
'miners_revenue_usd': ['Miners revenue', 'USD'], 'miners_revenue_usd': ['Miners revenue', 'USD'],
'btc_mined': ['Mined', 'BTC'], 'btc_mined': ['Mined', 'BTC'],
'trade_volume_usd': ['Trade volume', 'USD'], 'trade_volume_usd': ['Trade volume', 'USD'],
'difficulty': ['Difficulty', ''], 'difficulty': ['Difficulty', None],
'minutes_between_blocks': ['Time between Blocks', 'min'], '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'], 'hash_rate': ['Hash rate', 'PH/s'],
'timestamp': ['Timestamp', ''], 'timestamp': ['Timestamp', None],
'mined_blocks': ['Minded Blocks', ''], 'mined_blocks': ['Minded Blocks', None],
'blocks_size': ['Block size', ''], 'blocks_size': ['Block size', None],
'total_fees_btc': ['Total fees', 'BTC'], 'total_fees_btc': ['Total fees', 'BTC'],
'total_btc_sent': ['Total sent', 'BTC'], 'total_btc_sent': ['Total sent', 'BTC'],
'estimated_btc_sent': ['Estimated sent', 'BTC'], 'estimated_btc_sent': ['Estimated sent', 'BTC'],
'total_btc': ['Total', 'BTC'], 'total_btc': ['Total', 'BTC'],
'total_blocks': ['Total Blocks', ''], 'total_blocks': ['Total Blocks', None],
'next_retarget': ['Next retarget', ''], 'next_retarget': ['Next retarget', None],
'estimated_transaction_volume_usd': ['Est. Transaction volume', 'USD'], 'estimated_transaction_volume_usd': ['Est. Transaction volume', 'USD'],
'miners_revenue_btc': ['Miners revenue', 'BTC'], 'miners_revenue_btc': ['Miners revenue', 'BTC'],
'market_price_usd': ['Market price', 'USD'] '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__) _LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = { SENSOR_TYPES = {
'temperature': ['Temperature', ''], 'temperature': ['Temperature', None],
'humidity': ['Humidity', '%'] 'humidity': ['Humidity', '%']
} }
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,7 @@ from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['transmissionrpc==0.11'] REQUIREMENTS = ['transmissionrpc==0.11']
SENSOR_TYPES = { SENSOR_TYPES = {
'current_status': ['Status', ''], 'current_status': ['Status', None],
'download_speed': ['Down Speed', 'MB/s'], 'download_speed': ['Down Speed', 'MB/s'],
'upload_speed': ['Up 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? return TEMP_CELCIUS # can verisure report in fahrenheit?
def update(self): def update(self):
''' update sensor ''' """ update sensor """
verisure.update_climate() verisure.update_climate()
@ -96,5 +96,5 @@ class VerisureHygrometer(Entity):
return "%" return "%"
def update(self): def update(self):
''' update sensor ''' """ update sensor """
verisure.update_climate() verisure.update_climate()

View file

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

View file

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