mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
ps - add reload core config service (#2350)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""An abstract class for entities."""
|
||||
import logging
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE, ATTR_FRIENDLY_NAME, ATTR_HIDDEN, ATTR_ICON,
|
||||
@@ -10,8 +10,10 @@ from homeassistant.const import (
|
||||
from homeassistant.exceptions import NoEntitySpecifiedError
|
||||
from homeassistant.util import ensure_unique_string, slugify
|
||||
|
||||
# Dict mapping entity_id to a boolean that overwrites the hidden property
|
||||
_OVERWRITE = defaultdict(dict)
|
||||
# Entity attributes that we will overwrite
|
||||
_OVERWRITE = {}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Pattern for validating entity IDs (format: <domain>.<entity>)
|
||||
ENTITY_ID_PATTERN = re.compile(r"^(\w+)\.(\w+)$")
|
||||
@@ -22,7 +24,7 @@ def generate_entity_id(entity_id_format, name, current_ids=None, hass=None):
|
||||
name = (name or DEVICE_DEFAULT_NAME).lower()
|
||||
if current_ids is None:
|
||||
if hass is None:
|
||||
raise RuntimeError("Missing required parameter currentids or hass")
|
||||
raise ValueError("Missing required parameter currentids or hass")
|
||||
|
||||
current_ids = hass.states.entity_ids()
|
||||
|
||||
@@ -30,6 +32,13 @@ def generate_entity_id(entity_id_format, name, current_ids=None, hass=None):
|
||||
entity_id_format.format(slugify(name)), current_ids)
|
||||
|
||||
|
||||
def set_customize(customize):
|
||||
"""Overwrite all current customize settings."""
|
||||
global _OVERWRITE
|
||||
|
||||
_OVERWRITE = {key.lower(): val for key, val in customize.items()}
|
||||
|
||||
|
||||
def split_entity_id(entity_id):
|
||||
"""Split a state entity_id into domain, object_id."""
|
||||
return entity_id.split(".", 1)
|
||||
@@ -207,20 +216,6 @@ class Entity(object):
|
||||
"""Return the representation."""
|
||||
return "<Entity {}: {}>".format(self.name, self.state)
|
||||
|
||||
@staticmethod
|
||||
def overwrite_attribute(entity_id, attrs, vals):
|
||||
"""Overwrite any attribute of an entity.
|
||||
|
||||
This function should receive a list of attributes and a
|
||||
list of values. Set attribute to None to remove any overwritten
|
||||
value in place.
|
||||
"""
|
||||
for attr, val in zip(attrs, vals):
|
||||
if val is None:
|
||||
_OVERWRITE[entity_id.lower()].pop(attr, None)
|
||||
else:
|
||||
_OVERWRITE[entity_id.lower()][attr] = val
|
||||
|
||||
|
||||
class ToggleEntity(Entity):
|
||||
"""An abstract class for entities that can be turned on and off."""
|
||||
@@ -238,11 +233,13 @@ class ToggleEntity(Entity):
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the entity on."""
|
||||
pass
|
||||
_LOGGER.warning('Method turn_on not implemented for %s',
|
||||
self.entity_id)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the entity off."""
|
||||
pass
|
||||
_LOGGER.warning('Method turn_off not implemented for %s',
|
||||
self.entity_id)
|
||||
|
||||
def toggle(self, **kwargs):
|
||||
"""Toggle the entity off."""
|
||||
|
||||
Reference in New Issue
Block a user