Fix Z-Wave relative imports (#21693)

This commit is contained in:
Paulus Schoutsen 2019-03-05 17:17:58 -08:00 committed by GitHub
parent 467d8d616e
commit c9b173405b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 46 deletions

View file

@ -5,11 +5,14 @@ import homeassistant.util.dt as dt_util
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.event import track_point_in_time
from homeassistant.components import zwave
from homeassistant.components.zwave import workaround
from homeassistant.components.binary_sensor import (
DOMAIN,
BinarySensorDevice)
from . import (
workaround,
ZWaveDeviceEntity
)
from .const import COMMAND_CLASS_SENSOR_BINARY
_LOGGER = logging.getLogger(__name__)
@ -40,17 +43,17 @@ def get_device(values, **kwargs):
if workaround.get_device_component_mapping(values.primary) == DOMAIN:
return ZWaveBinarySensor(values, None)
if values.primary.command_class == zwave.const.COMMAND_CLASS_SENSOR_BINARY:
if values.primary.command_class == COMMAND_CLASS_SENSOR_BINARY:
return ZWaveBinarySensor(values, None)
return None
class ZWaveBinarySensor(BinarySensorDevice, zwave.ZWaveDeviceEntity):
class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
"""Representation of a binary sensor within Z-Wave."""
def __init__(self, values, device_class):
"""Initialize the sensor."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self._sensor_type = device_class
self._state = self.values.primary.data

View file

@ -7,10 +7,10 @@ from homeassistant.components.climate.const import (
DOMAIN, STATE_AUTO, STATE_COOL, STATE_HEAT,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE,
SUPPORT_OPERATION_MODE, SUPPORT_SWING_MODE)
from homeassistant.components.zwave import ZWaveDeviceEntity
from homeassistant.const import (
STATE_OFF, TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_TEMPERATURE)
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import ZWaveDeviceEntity
_LOGGER = logging.getLogger(__name__)

View file

@ -4,10 +4,9 @@ from homeassistant.core import callback
from homeassistant.components.cover import (
DOMAIN, SUPPORT_OPEN, SUPPORT_CLOSE, ATTR_POSITION)
from homeassistant.components import zwave
from homeassistant.components.zwave import (
ZWaveDeviceEntity, workaround)
from homeassistant.components.cover import CoverDevice
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import ZWaveDeviceEntity, workaround
_LOGGER = logging.getLogger(__name__)

View file

@ -6,8 +6,8 @@ from homeassistant.core import callback
from homeassistant.components.fan import (
DOMAIN, FanEntity, SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
SUPPORT_SET_SPEED)
from homeassistant.components import zwave
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import ZWaveDeviceEntity
_LOGGER = logging.getLogger(__name__)
@ -52,12 +52,12 @@ def get_device(values, **kwargs):
return ZwaveFan(values)
class ZwaveFan(zwave.ZWaveDeviceEntity, FanEntity):
class ZwaveFan(ZWaveDeviceEntity, FanEntity):
"""Representation of a Z-Wave fan."""
def __init__(self, values):
"""Initialize the Z-Wave fan device."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self.update_properties()
def update_properties(self):

View file

@ -7,10 +7,15 @@ from homeassistant.components.light import (
ATTR_WHITE_VALUE, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR,
ATTR_TRANSITION, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_COLOR,
SUPPORT_TRANSITION, SUPPORT_WHITE_VALUE, DOMAIN, Light)
from homeassistant.components import zwave
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers.dispatcher import async_dispatcher_connect
import homeassistant.util.color as color_util
from . import (
CONF_REFRESH_VALUE,
CONF_REFRESH_DELAY,
const,
ZWaveDeviceEntity,
)
_LOGGER = logging.getLogger(__name__)
@ -68,13 +73,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def get_device(node, values, node_config, **kwargs):
"""Create Z-Wave entity device."""
refresh = node_config.get(zwave.CONF_REFRESH_VALUE)
delay = node_config.get(zwave.CONF_REFRESH_DELAY)
refresh = node_config.get(CONF_REFRESH_VALUE)
delay = node_config.get(CONF_REFRESH_DELAY)
_LOGGER.debug("node=%d value=%d node_config=%s CONF_REFRESH_VALUE=%s"
" CONF_REFRESH_DELAY=%s", node.node_id,
values.primary.value_id, node_config, refresh, delay)
if node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_COLOR):
if node.has_command_class(const.COMMAND_CLASS_SWITCH_COLOR):
return ZwaveColorLight(values, refresh, delay)
return ZwaveDimmer(values, refresh, delay)
@ -104,12 +109,12 @@ def ct_to_hs(temp):
return [int(val) for val in colorlist]
class ZwaveDimmer(zwave.ZWaveDeviceEntity, Light):
class ZwaveDimmer(ZWaveDeviceEntity, Light):
"""Representation of a Z-Wave dimmer."""
def __init__(self, values, refresh, delay):
"""Initialize the light."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self._brightness = None
self._state = None
self._supported_features = None

View file

@ -5,9 +5,9 @@ import voluptuous as vol
from homeassistant.core import callback
from homeassistant.components.lock import DOMAIN, LockDevice
from homeassistant.components import zwave
from homeassistant.helpers.dispatcher import async_dispatcher_connect
import homeassistant.helpers.config_validation as cv
from . import ZWaveDeviceEntity, const
_LOGGER = logging.getLogger(__name__)
@ -135,18 +135,18 @@ ALARM_TYPE_STD = [
]
SET_USERCODE_SCHEMA = vol.Schema({
vol.Required(zwave.const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(ATTR_CODE_SLOT): vol.Coerce(int),
vol.Required(ATTR_USERCODE): cv.string,
})
GET_USERCODE_SCHEMA = vol.Schema({
vol.Required(zwave.const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(ATTR_CODE_SLOT): vol.Coerce(int),
})
CLEAR_USERCODE_SCHEMA = vol.Schema({
vol.Required(zwave.const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(ATTR_CODE_SLOT): vol.Coerce(int),
})
@ -166,17 +166,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_dispatcher_connect(hass, 'zwave_new_lock', async_add_lock)
network = hass.data[zwave.const.DATA_NETWORK]
network = hass.data[const.DATA_NETWORK]
def set_usercode(service):
"""Set the usercode to index X on the lock."""
node_id = service.data.get(zwave.const.ATTR_NODE_ID)
node_id = service.data.get(const.ATTR_NODE_ID)
lock_node = network.nodes[node_id]
code_slot = service.data.get(ATTR_CODE_SLOT)
usercode = service.data.get(ATTR_USERCODE)
for value in lock_node.get_values(
class_id=zwave.const.COMMAND_CLASS_USER_CODE).values():
class_id=const.COMMAND_CLASS_USER_CODE).values():
if value.index != code_slot:
continue
if len(str(usercode)) < 4:
@ -190,12 +190,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def get_usercode(service):
"""Get a usercode at index X on the lock."""
node_id = service.data.get(zwave.const.ATTR_NODE_ID)
node_id = service.data.get(const.ATTR_NODE_ID)
lock_node = network.nodes[node_id]
code_slot = service.data.get(ATTR_CODE_SLOT)
for value in lock_node.get_values(
class_id=zwave.const.COMMAND_CLASS_USER_CODE).values():
class_id=const.COMMAND_CLASS_USER_CODE).values():
if value.index != code_slot:
continue
_LOGGER.info("Usercode at slot %s is: %s", value.index, value.data)
@ -203,13 +203,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def clear_usercode(service):
"""Set usercode to slot X on the lock."""
node_id = service.data.get(zwave.const.ATTR_NODE_ID)
node_id = service.data.get(const.ATTR_NODE_ID)
lock_node = network.nodes[node_id]
code_slot = service.data.get(ATTR_CODE_SLOT)
data = ''
for value in lock_node.get_values(
class_id=zwave.const.COMMAND_CLASS_USER_CODE).values():
class_id=const.COMMAND_CLASS_USER_CODE).values():
if value.index != code_slot:
continue
for i in range(len(value.data)):
@ -236,12 +236,12 @@ def get_device(node, values, **kwargs):
return ZwaveLock(values)
class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice):
class ZwaveLock(ZWaveDeviceEntity, LockDevice):
"""Representation of a Z-Wave Lock."""
def __init__(self, values):
"""Initialize the Z-Wave lock device."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self._state = None
self._notification = None
self._lock_status = None
@ -297,12 +297,12 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice):
if self._track_message_workaround:
this_message = self.node.stats['lastReceivedMessage'][5]
if this_message == zwave.const.COMMAND_CLASS_DOOR_LOCK:
if this_message == const.COMMAND_CLASS_DOOR_LOCK:
self._state = self.values.primary.data
_LOGGER.debug("set state to %s based on message tracking",
self._state)
if self._previous_message == \
zwave.const.COMMAND_CLASS_DOOR_LOCK:
const.COMMAND_CLASS_DOOR_LOCK:
if self._state:
self._notification = \
LOCK_NOTIFICATION[NOTIFICATION_RF_LOCK]

View file

@ -2,10 +2,12 @@
import logging
from homeassistant.core import callback
from homeassistant.components.sensor import DOMAIN
from homeassistant.components import zwave
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import (
const,
ZWaveDeviceEntity,
)
_LOGGER = logging.getLogger(__name__)
@ -28,23 +30,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
def get_device(node, values, **kwargs):
"""Create Z-Wave entity device."""
# Generic Device mappings
if node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_MULTILEVEL):
if node.has_command_class(const.COMMAND_CLASS_SENSOR_MULTILEVEL):
return ZWaveMultilevelSensor(values)
if node.has_command_class(zwave.const.COMMAND_CLASS_METER) and \
values.primary.type == zwave.const.TYPE_DECIMAL:
if node.has_command_class(const.COMMAND_CLASS_METER) and \
values.primary.type == const.TYPE_DECIMAL:
return ZWaveMultilevelSensor(values)
if node.has_command_class(zwave.const.COMMAND_CLASS_ALARM) or \
node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_ALARM):
if node.has_command_class(const.COMMAND_CLASS_ALARM) or \
node.has_command_class(const.COMMAND_CLASS_SENSOR_ALARM):
return ZWaveAlarmSensor(values)
return None
class ZWaveSensor(zwave.ZWaveDeviceEntity):
class ZWaveSensor(ZWaveDeviceEntity):
"""Representation of a Z-Wave sensor."""
def __init__(self, values):
"""Initialize the sensor."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self.update_properties()
def update_properties(self):

View file

@ -3,8 +3,11 @@ import logging
import time
from homeassistant.core import callback
from homeassistant.components.switch import DOMAIN, SwitchDevice
from homeassistant.components import zwave
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import (
ZWaveDeviceEntity,
workaround,
)
_LOGGER = logging.getLogger(__name__)
@ -30,15 +33,15 @@ def get_device(values, **kwargs):
return ZwaveSwitch(values)
class ZwaveSwitch(zwave.ZWaveDeviceEntity, SwitchDevice):
class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
"""Representation of a Z-Wave switch."""
def __init__(self, values):
"""Initialize the Z-Wave switch device."""
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self.refresh_on_update = (
zwave.workaround.get_device_mapping(values.primary) ==
zwave.workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE)
workaround.get_device_mapping(values.primary) ==
workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE)
self.last_update = time.perf_counter()
self._state = self.values.primary.data