mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add assumed_state property to entity
This commit is contained in:
parent
e170484f16
commit
8bea5c06de
@ -12,17 +12,18 @@ from homeassistant.const import DEVICE_DEFAULT_NAME
|
|||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Find and return demo switches. """
|
""" Find and return demo switches. """
|
||||||
add_devices_callback([
|
add_devices_callback([
|
||||||
DemoSwitch('Decorative Lights', True, None),
|
DemoSwitch('Decorative Lights', True, None, True),
|
||||||
DemoSwitch('AC', False, 'mdi:air-conditioner')
|
DemoSwitch('AC', False, 'mdi:air-conditioner', False)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class DemoSwitch(SwitchDevice):
|
class DemoSwitch(SwitchDevice):
|
||||||
""" Provides a demo switch. """
|
""" Provides a demo switch. """
|
||||||
def __init__(self, name, state, icon):
|
def __init__(self, name, state, icon, assumed):
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
self._state = state
|
self._state = state
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
|
self._assumed = assumed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -39,6 +40,11 @@ class DemoSwitch(SwitchDevice):
|
|||||||
""" Returns the icon to use for device if any. """
|
""" Returns the icon to use for device if any. """
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def assumed_state(self):
|
||||||
|
"""Return if the state is based on assumptions."""
|
||||||
|
return self._assumed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_mwh(self):
|
||||||
""" Current power usage in mwh. """
|
""" Current power usage in mwh. """
|
||||||
|
@ -124,6 +124,9 @@ ATTR_LONGITUDE = "longitude"
|
|||||||
# Accuracy of location in meters
|
# Accuracy of location in meters
|
||||||
ATTR_GPS_ACCURACY = 'gps_accuracy'
|
ATTR_GPS_ACCURACY = 'gps_accuracy'
|
||||||
|
|
||||||
|
# If state is assumed
|
||||||
|
ATTR_ASSUMED_STATE = 'assumed_state'
|
||||||
|
|
||||||
# #### SERVICES ####
|
# #### SERVICES ####
|
||||||
SERVICE_HOMEASSISTANT_STOP = "stop"
|
SERVICE_HOMEASSISTANT_STOP = "stop"
|
||||||
SERVICE_HOMEASSISTANT_RESTART = "restart"
|
SERVICE_HOMEASSISTANT_RESTART = "restart"
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.util import ensure_unique_string, slugify
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_FRIENDLY_NAME, ATTR_HIDDEN, ATTR_UNIT_OF_MEASUREMENT, ATTR_ICON,
|
ATTR_FRIENDLY_NAME, ATTR_HIDDEN, ATTR_UNIT_OF_MEASUREMENT, ATTR_ICON,
|
||||||
DEVICE_DEFAULT_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE,
|
DEVICE_DEFAULT_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE,
|
||||||
TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_ASSUMED_STATE)
|
||||||
|
|
||||||
# Dict mapping entity_id to a boolean that overwrites the hidden property
|
# Dict mapping entity_id to a boolean that overwrites the hidden property
|
||||||
_OVERWRITE = defaultdict(dict)
|
_OVERWRITE = defaultdict(dict)
|
||||||
@ -116,6 +116,11 @@ class Entity(object):
|
|||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def assumed_state(self):
|
||||||
|
"""Return True if unable to access real state of entity."""
|
||||||
|
return False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
pass
|
pass
|
||||||
@ -164,12 +169,15 @@ class Entity(object):
|
|||||||
if ATTR_FRIENDLY_NAME not in attr and self.name is not None:
|
if ATTR_FRIENDLY_NAME not in attr and self.name is not None:
|
||||||
attr[ATTR_FRIENDLY_NAME] = str(self.name)
|
attr[ATTR_FRIENDLY_NAME] = str(self.name)
|
||||||
|
|
||||||
if ATTR_ICON not in attr and self.icon is not None:
|
if self.icon is not None:
|
||||||
attr[ATTR_ICON] = str(self.icon)
|
attr[ATTR_ICON] = str(self.icon)
|
||||||
|
|
||||||
if self.hidden:
|
if self.hidden:
|
||||||
attr[ATTR_HIDDEN] = bool(self.hidden)
|
attr[ATTR_HIDDEN] = bool(self.hidden)
|
||||||
|
|
||||||
|
if self.assumed_state:
|
||||||
|
attr[ATTR_ASSUMED_STATE] = bool(self.assumed_state)
|
||||||
|
|
||||||
# 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, {}))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user