Add entity_picture property

This commit is contained in:
Paulus Schoutsen committed 2016-02-23 22:41:24 -08:00
1 parent 8dc6443d14
commit 967a751da1
7 files changed
+67 -45

No files matched your search

@@ -7,7 +7,7 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.steam_online/
"""
from homeassistant.helpers.entity import Entity
from homeassistant.const import (ATTR_ENTITY_PICTURE, CONF_API_KEY)
from homeassistant.const import CONF_API_KEY
ICON = 'mdi:steam'
@@ -62,11 +62,9 @@ class SteamSensor(Entity):
}.get(self._profile.status, 'Offline')
@property
def device_state_attributes(self):
""" Returns the state attributes. """
return {
ATTR_ENTITY_PICTURE: self._profile.avatar_medium
}
def entity_picture(self):
"""Avatar of the account."""
return self._profile.avatar_medium
@property
def icon(self):
+6 -2
View File
@@ -4,7 +4,6 @@ Support for the Twitch stream status.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.twitch/
"""
from homeassistant.const import ATTR_ENTITY_PICTURE
from homeassistant.helpers.entity import Entity
STATE_STREAMING = 'streaming'
@@ -51,6 +50,11 @@ class TwitchSensor(Entity):
"""State of the sensor."""
return self._state
@property
def entity_picture(self):
"""Preview of current game."""
return self._preview
# pylint: disable=no-member
def update(self):
"""Update device state."""
@@ -62,6 +66,7 @@ class TwitchSensor(Entity):
self._preview = stream.get('preview').get('small')
self._state = STATE_STREAMING
else:
self._preview = None
self._state = STATE_OFFLINE
@property
@@ -71,7 +76,6 @@ class TwitchSensor(Entity):
return {
ATTR_GAME: self._game,
ATTR_TITLE: self._title,
ATTR_ENTITY_PICTURE: self._preview
}
@property
+10 -10
View File
@@ -8,8 +8,7 @@ import logging
import requests
from homeassistant.const import (
ATTR_ENTITY_PICTURE, CONF_LATITUDE, CONF_LONGITUDE)
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.helpers.entity import Entity
from homeassistant.util import dt as dt_util
from homeassistant.util import location
@@ -97,20 +96,21 @@ class YrSensor(Entity):
"""Returns the state of the device."""
return self._state
@property
def entity_picture(self):
"""Weather symbol if type is symbol."""
if self.type != 'symbol':
return None
return "http://api.met.no/weatherapi/weathericon/1.1/" \
"?symbol={0};content_type=image/png".format(self._state)
@property
def device_state_attributes(self):
"""Returns state attributes. """
data = {
return {
'about': "Weather forecast from yr.no, delivered by the"
" Norwegian Meteorological Institute and the NRK"
}
if self.type == 'symbol':
symbol_nr = self._state
data[ATTR_ENTITY_PICTURE] = \
"http://api.met.no/weatherapi/weathericon/1.1/" \
"?symbol={0};content_type=image/png".format(symbol_nr)
return data
@property
def unit_of_measurement(self):