本文整理汇总了Python中homeassistant.helpers.entity.Entity方法的典型用法代码示例。如果您正苦于以下问题:Python entity.Entity方法的具体用法?Python entity.Entity怎么用?Python entity.Entity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.helpers.entity
的用法示例。
在下文中一共展示了entity.Entity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: async_update
# 需要导入模块: from homeassistant.helpers import entity [as 别名]
# 或者: from homeassistant.helpers.entity import Entity [as 别名]
def async_update(self):
state = self.hass.states.get(self._entity_id)
if not state:
_LOGGER.error('Entity does not exists')
self._state = STATE_UNKNOWN
return
forecasts = state.attributes.get('forecast')
if not forecasts:
_LOGGER.error('There is no forecast')
self._state = STATE_OFF
return
self._state = STATE_OFF
for forecast in forecasts[0:9]:
if forecast['precipitation']:
precipitation = float(forecast['precipitation'])
if precipitation and precipitation >= 0.0:
self._state = STATE_ON
示例2: async_entity_update
# 需要导入模块: from homeassistant.helpers import entity [as 别名]
# 或者: from homeassistant.helpers.entity import Entity [as 别名]
def async_entity_update(self):
"""Update the entity."""
_LOGGER.debug("Entity update triggered on %s", self)
self.async_schedule_update_ha_state(True)
示例3: handle_entity_update
# 需要导入模块: from homeassistant.helpers import entity [as 别名]
# 或者: from homeassistant.helpers.entity import Entity [as 别名]
def handle_entity_update(self, msg):
"""Update entity state."""
_LOGGER.debug(f"Entity Update: {msg}")
self.attr = msg.get("attributes", {})
self._state = msg[CONF_STATE]
self.async_write_ha_state()
示例4: __init__
# 需要导入模块: from homeassistant.helpers import entity [as 别名]
# 或者: from homeassistant.helpers.entity import Entity [as 别名]
def __init__(self, hass, devicetracker_id, name, api_key, options, home_zone, map_provider, map_zoom):
"""Initialize the sensor."""
self._hass = hass
self._name = name
self._api_key = api_key
self._options = options.lower()
self._devicetracker_id = devicetracker_id.lower()
self._home_zone = home_zone.lower()
self._map_provider = map_provider.lower()
self._map_zoom = map_zoom.lower()
self._state = "Initializing... (since 99:99)"
home_latitude = str(hass.states.get(home_zone).attributes.get('latitude'))
home_longitude = str(hass.states.get(home_zone).attributes.get('longitude'))
self._entity_picture = hass.states.get(devicetracker_id).attributes.get('entity_picture') if hass.states.get(devicetracker_id) else None
self._street_number = None
self._street = None
self._city = None
self._postal_town = None
self._postal_code = None
self._city = None
self._region = None
self._country = None
self._county = None
self._formatted_address = None
self._place_type = None
self._place_name = None
self._place_category = None
self._place_neighbourhood = None
self._home_latitude = home_latitude
self._home_longitude = home_longitude
self._latitude_old = home_latitude
self._longitude_old = home_longitude
self._latitude = home_latitude
self._longitude = home_longitude
self._devicetracker_zone = 'Home'
self._mtime = str(datetime.now())
self._distance_km = 0
self._distance_m = 0
self._location_current = home_latitude + ',' + home_longitude
self._location_previous = home_latitude + ',' + home_longitude
self._updateskipped = 0
self._direction = 'stationary'
self._map_link = None
#'https://www.google.com/maps/@' + home_latitude + "," + home_longitude + ',19z'
# Check if devicetracker_id was specified correctly
_LOGGER.info( "(" + self._name + ") DeviceTracker Entity ID is " + devicetracker_id.split('.', 1)[1] )
if devicetracker_id.split('.', 1)[0] in TRACKABLE_DOMAINS:
self._devicetracker_id = devicetracker_id
track_state_change(hass, self._devicetracker_id, self.tsc_update, from_state=None, to_state=None)
_LOGGER.info( "(" + self._name + ") Now subscribed to state change events from " + self._devicetracker_id )