Remove Z-Wave old/new entity_id attributes (#12652)
This commit is contained in:
parent
f164a5a65f
commit
dc8424032b
5 changed files with 19 additions and 98 deletions
|
@ -20,7 +20,7 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_ID, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.helpers.entity_values import EntityValues
|
||||
from homeassistant.helpers.event import track_time_change
|
||||
from homeassistant.util import convert, slugify
|
||||
from homeassistant.util import convert
|
||||
import homeassistant.util.dt as dt_util
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
|
@ -52,7 +52,6 @@ CONF_DEVICE_CONFIG = 'device_config'
|
|||
CONF_DEVICE_CONFIG_GLOB = 'device_config_glob'
|
||||
CONF_DEVICE_CONFIG_DOMAIN = 'device_config_domain'
|
||||
CONF_NETWORK_KEY = 'network_key'
|
||||
CONF_NEW_ENTITY_IDS = 'new_entity_ids'
|
||||
|
||||
ATTR_POWER = 'power_consumption'
|
||||
|
||||
|
@ -161,7 +160,6 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
cv.positive_int,
|
||||
vol.Optional(CONF_USB_STICK_PATH, default=DEFAULT_CONF_USB_STICK_PATH):
|
||||
cv.string,
|
||||
vol.Optional(CONF_NEW_ENTITY_IDS, default=True): cv.boolean,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -178,27 +176,6 @@ def _value_name(value):
|
|||
return '{} {}'.format(node_name(value.node), value.label).strip()
|
||||
|
||||
|
||||
def _node_object_id(node):
|
||||
"""Return the object_id of the node."""
|
||||
node_object_id = '{}_{}'.format(slugify(node_name(node)), node.node_id)
|
||||
return node_object_id
|
||||
|
||||
|
||||
def object_id(value):
|
||||
"""Return the object_id of the device value.
|
||||
|
||||
The object_id contains node_id and value instance id
|
||||
to not collide with other entity_ids.
|
||||
"""
|
||||
_object_id = "{}_{}_{}".format(slugify(_value_name(value)),
|
||||
value.node.node_id, value.index)
|
||||
|
||||
# Add the instance id if there is more than one instance for the value
|
||||
if value.instance > 1:
|
||||
return '{}_{}'.format(_object_id, value.instance)
|
||||
return _object_id
|
||||
|
||||
|
||||
def nice_print_node(node):
|
||||
"""Print a nice formatted node to the output (debug method)."""
|
||||
node_dict = _obj_to_dict(node)
|
||||
|
@ -260,13 +237,6 @@ def setup(hass, config):
|
|||
config[DOMAIN][CONF_DEVICE_CONFIG],
|
||||
config[DOMAIN][CONF_DEVICE_CONFIG_DOMAIN],
|
||||
config[DOMAIN][CONF_DEVICE_CONFIG_GLOB])
|
||||
new_entity_ids = config[DOMAIN][CONF_NEW_ENTITY_IDS]
|
||||
if not new_entity_ids:
|
||||
_LOGGER.warning(
|
||||
"ZWave entity_ids will soon be changing. To opt in to new "
|
||||
"entity_ids now, set `new_entity_ids: true` under zwave in your "
|
||||
"configuration.yaml. See the following blog post for details: "
|
||||
"https://home-assistant.io/blog/2017/06/15/zwave-entity-ids/")
|
||||
|
||||
# Setup options
|
||||
options = ZWaveOption(
|
||||
|
@ -328,12 +298,9 @@ def setup(hass, config):
|
|||
|
||||
def node_added(node):
|
||||
"""Handle a new node on the network."""
|
||||
entity = ZWaveNodeEntity(node, network, new_entity_ids)
|
||||
entity = ZWaveNodeEntity(node, network)
|
||||
name = node_name(node)
|
||||
if new_entity_ids:
|
||||
generated_id = generate_entity_id(DOMAIN + '.{}', name, [])
|
||||
else:
|
||||
generated_id = entity.entity_id
|
||||
generated_id = generate_entity_id(DOMAIN + '.{}', name, [])
|
||||
node_config = device_config.get(generated_id)
|
||||
if node_config.get(CONF_IGNORED):
|
||||
_LOGGER.info(
|
||||
|
@ -794,11 +761,7 @@ class ZWaveDeviceEntityValues():
|
|||
component = workaround_component
|
||||
|
||||
value_name = _value_name(self.primary)
|
||||
if self._zwave_config[DOMAIN][CONF_NEW_ENTITY_IDS]:
|
||||
generated_id = generate_entity_id(
|
||||
component + '.{}', value_name, [])
|
||||
else:
|
||||
generated_id = "{}.{}".format(component, object_id(self.primary))
|
||||
generated_id = generate_entity_id(component + '.{}', value_name, [])
|
||||
node_config = self._device_config.get(generated_id)
|
||||
|
||||
# Configure node
|
||||
|
@ -831,12 +794,6 @@ class ZWaveDeviceEntityValues():
|
|||
self._workaround_ignore = True
|
||||
return
|
||||
|
||||
device.old_entity_id = "{}.{}".format(
|
||||
component, object_id(self.primary))
|
||||
device.new_entity_id = "{}.{}".format(component, slugify(device.name))
|
||||
if not self._zwave_config[DOMAIN][CONF_NEW_ENTITY_IDS]:
|
||||
device.entity_id = device.old_entity_id
|
||||
|
||||
self._entity = device
|
||||
|
||||
dict_id = id(self)
|
||||
|
@ -932,8 +889,6 @@ class ZWaveDeviceEntity(ZWaveBaseEntity):
|
|||
const.ATTR_VALUE_INDEX: self.values.primary.index,
|
||||
const.ATTR_VALUE_INSTANCE: self.values.primary.instance,
|
||||
const.ATTR_VALUE_ID: str(self.values.primary.value_id),
|
||||
'old_entity_id': self.old_entity_id,
|
||||
'new_entity_id': self.new_entity_id,
|
||||
}
|
||||
|
||||
if self.power_consumption is not None:
|
||||
|
|
|
@ -7,7 +7,6 @@ ATTR_ASSOCIATION = "association"
|
|||
ATTR_INSTANCE = "instance"
|
||||
ATTR_GROUP = "group"
|
||||
ATTR_VALUE_ID = "value_id"
|
||||
ATTR_OBJECT_ID = "object_id"
|
||||
ATTR_MESSAGES = "messages"
|
||||
ATTR_NAME = "name"
|
||||
ATTR_RETURN_ROUTES = "return_routes"
|
||||
|
|
|
@ -4,11 +4,10 @@ import logging
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_WAKEUP, ATTR_ENTITY_ID
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import (
|
||||
ATTR_NODE_ID, COMMAND_CLASS_WAKE_UP, ATTR_SCENE_ID, ATTR_SCENE_DATA,
|
||||
ATTR_BASIC_LEVEL, EVENT_NODE_EVENT, EVENT_SCENE_ACTIVATED, DOMAIN,
|
||||
ATTR_BASIC_LEVEL, EVENT_NODE_EVENT, EVENT_SCENE_ACTIVATED,
|
||||
COMMAND_CLASS_CENTRAL_SCENE)
|
||||
from .util import node_name
|
||||
|
||||
|
@ -41,8 +40,6 @@ class ZWaveBaseEntity(Entity):
|
|||
def __init__(self):
|
||||
"""Initialize the base Z-Wave class."""
|
||||
self._update_scheduled = False
|
||||
self.old_entity_id = None
|
||||
self.new_entity_id = None
|
||||
|
||||
def maybe_schedule_update(self):
|
||||
"""Maybe schedule state update.
|
||||
|
@ -72,7 +69,7 @@ class ZWaveBaseEntity(Entity):
|
|||
class ZWaveNodeEntity(ZWaveBaseEntity):
|
||||
"""Representation of a Z-Wave node."""
|
||||
|
||||
def __init__(self, node, network, new_entity_ids):
|
||||
def __init__(self, node, network):
|
||||
"""Initialize node."""
|
||||
# pylint: disable=import-error
|
||||
super().__init__()
|
||||
|
@ -84,11 +81,6 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
self._name = node_name(self.node)
|
||||
self._product_name = node.product_name
|
||||
self._manufacturer_name = node.manufacturer_name
|
||||
self.old_entity_id = "{}.{}_{}".format(
|
||||
DOMAIN, slugify(self._name), self.node_id)
|
||||
self.new_entity_id = "{}.{}".format(DOMAIN, slugify(self._name))
|
||||
if not new_entity_ids:
|
||||
self.entity_id = self.old_entity_id
|
||||
self._attributes = {}
|
||||
self.wakeup_interval = None
|
||||
self.location = None
|
||||
|
@ -229,8 +221,6 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
ATTR_NODE_NAME: self._name,
|
||||
ATTR_MANUFACTURER_NAME: self._manufacturer_name,
|
||||
ATTR_PRODUCT_NAME: self._product_name,
|
||||
'old_entity_id': self.old_entity_id,
|
||||
'new_entity_id': self.new_entity_id,
|
||||
}
|
||||
attrs.update(self._attributes)
|
||||
if self.battery_level is not None:
|
||||
|
|
|
@ -213,9 +213,7 @@ def test_node_discovery(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -237,7 +235,6 @@ def test_node_ignored(hass, mock_openzwave):
|
|||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
'device_config': {
|
||||
'zwave.mock_node': {
|
||||
'ignored': True,
|
||||
|
@ -262,9 +259,7 @@ def test_value_discovery(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -289,9 +284,7 @@ def test_value_discovery_existing_entity(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -336,9 +329,7 @@ def test_power_schemes(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -380,9 +371,7 @@ def test_network_ready(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -409,9 +398,7 @@ def test_network_complete(hass, mock_openzwave):
|
|||
mock_receivers.append(receiver)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -441,9 +428,7 @@ class TestZWaveDeviceEntityValues(unittest.TestCase):
|
|||
self.hass = get_test_home_assistant()
|
||||
self.hass.start()
|
||||
|
||||
setup_component(self.hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
setup_component(self.hass, 'zwave', {'zwave': {}})
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.node = MockNode()
|
||||
|
@ -472,9 +457,7 @@ class TestZWaveDeviceEntityValues(unittest.TestCase):
|
|||
command_class='mock_bad_class', node=self.node)
|
||||
|
||||
self.entity_id = 'mock_component.mock_node_mock_value'
|
||||
self.zwave_config = {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}}
|
||||
self.zwave_config = {'zwave': {}}
|
||||
self.device_config = {self.entity_id: {}}
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
|
@ -781,9 +764,7 @@ class TestZWaveServices(unittest.TestCase):
|
|||
self.hass.start()
|
||||
|
||||
# Initialize zwave
|
||||
setup_component(self.hass, 'zwave', {'zwave': {
|
||||
'new_entity_ids': True,
|
||||
}})
|
||||
setup_component(self.hass, 'zwave', {'zwave': {}})
|
||||
self.hass.block_till_done()
|
||||
self.zwave_network = self.hass.data[DATA_NETWORK]
|
||||
self.zwave_network.state = MockNetwork.STATE_READY
|
||||
|
|
|
@ -43,7 +43,7 @@ def test_node_event_activated(hass, mock_openzwave):
|
|||
node = mock_zwave.MockNode(node_id=11)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave, True)
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -86,7 +86,7 @@ def test_scene_activated(hass, mock_openzwave):
|
|||
node = mock_zwave.MockNode(node_id=11)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave, True)
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -129,7 +129,7 @@ def test_central_scene_activated(hass, mock_openzwave):
|
|||
node = mock_zwave.MockNode(node_id=11)
|
||||
|
||||
with patch('pydispatch.dispatcher.connect', new=mock_connect):
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave, True)
|
||||
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
|
||||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
|
@ -185,7 +185,7 @@ class TestZWaveNodeEntity(unittest.TestCase):
|
|||
self.node.manufacturer_name = 'Test Manufacturer'
|
||||
self.node.product_name = 'Test Product'
|
||||
self.entity = node_entity.ZWaveNodeEntity(self.node,
|
||||
self.zwave_network, True)
|
||||
self.zwave_network)
|
||||
|
||||
def test_network_node_changed_from_value(self):
|
||||
"""Test for network_node_changed."""
|
||||
|
@ -226,8 +226,6 @@ class TestZWaveNodeEntity(unittest.TestCase):
|
|||
{'node_id': self.node.node_id,
|
||||
'node_name': 'Mock Node',
|
||||
'manufacturer_name': 'Test Manufacturer',
|
||||
'old_entity_id': 'zwave.mock_node_567',
|
||||
'new_entity_id': 'zwave.mock_node',
|
||||
'product_name': 'Test Product'},
|
||||
self.entity.device_state_attributes)
|
||||
|
||||
|
@ -286,8 +284,6 @@ class TestZWaveNodeEntity(unittest.TestCase):
|
|||
{'node_id': self.node.node_id,
|
||||
'node_name': 'Mock Node',
|
||||
'manufacturer_name': 'Test Manufacturer',
|
||||
'old_entity_id': 'zwave.mock_node_567',
|
||||
'new_entity_id': 'zwave.mock_node',
|
||||
'product_name': 'Test Product',
|
||||
'query_stage': 'Dynamic',
|
||||
'is_awake': True,
|
||||
|
|
Loading…
Add table
Reference in a new issue