Skip to content

Commit

Permalink
Create a file for zwave workarounds. (#5798)
Browse files Browse the repository at this point in the history
* Create a file for zwave workarounds. Add sensor->binary_sensor for fgfs101 (#2)

* Don't use default None
  • Loading branch information
andrey-git authored and balloob committed Feb 8, 2017
1 parent b8a0792 commit 1b54218
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 36 deletions.
47 changes: 14 additions & 33 deletions homeassistant/components/binary_sensor/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,14 @@
import homeassistant.util.dt as dt_util
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)

_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = []

PHILIO = 0x013c
PHILIO_SLIM_SENSOR = 0x0002
PHILIO_SLIM_SENSOR_MOTION = (PHILIO, PHILIO_SLIM_SENSOR, 0)
PHILIO_3_IN_1_SENSOR_GEN_4 = 0x000d
PHILIO_3_IN_1_SENSOR_GEN_4_MOTION = (PHILIO, PHILIO_3_IN_1_SENSOR_GEN_4, 0)
WENZHOU = 0x0118
WENZHOU_SLIM_SENSOR_MOTION = (WENZHOU, PHILIO_SLIM_SENSOR, 0)

WORKAROUND_NO_OFF_EVENT = 'trigger_no_off_event'

DEVICE_MAPPINGS = {
PHILIO_SLIM_SENSOR_MOTION: WORKAROUND_NO_OFF_EVENT,
PHILIO_3_IN_1_SENSOR_GEN_4_MOTION: WORKAROUND_NO_OFF_EVENT,
WENZHOU_SLIM_SENSOR_MOTION: WORKAROUND_NO_OFF_EVENT,
}


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Z-Wave platform for binary sensors."""
Expand All @@ -42,23 +27,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
value = node.values[discovery_info[zwave.const.ATTR_VALUE_ID]]
value.set_change_verified(False)

# Make sure that we have values for the key before converting to int
if (value.node.manufacturer_id.strip() and
value.node.product_id.strip()):
specific_sensor_key = (int(value.node.manufacturer_id, 16),
int(value.node.product_id, 16),
value.index)

if specific_sensor_key in DEVICE_MAPPINGS:
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_NO_OFF_EVENT:
# Default the multiplier to 4
re_arm_multiplier = (zwave.get_config_value(value.node,
9) or 4)
add_devices([
ZWaveTriggerSensor(value, "motion",
hass, re_arm_multiplier * 8)
])
return
device_mapping = workaround.get_device_mapping(value)
if device_mapping == workaround.WORKAROUND_NO_OFF_EVENT:
# Default the multiplier to 4
re_arm_multiplier = (zwave.get_config_value(value.node, 9) or 4)
add_devices([
ZWaveTriggerSensor(value, "motion",
hass, re_arm_multiplier * 8)
])
return

if workaround.get_device_component_mapping(value) == DOMAIN:
add_devices([ZWaveBinarySensor(value, None)])
return

if value.command_class == zwave.const.COMMAND_CLASS_SENSOR_BINARY:
add_devices([ZWaveBinarySensor(value, None)])
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import homeassistant.config as conf_util
import homeassistant.helpers.config_validation as cv
from . import const
from . import workaround

REQUIREMENTS = ['pydispatcher==2.0.5']

Expand Down Expand Up @@ -343,12 +344,18 @@ def value_added(node, value):
_LOGGER.debug("Adding Node_id=%s Generic_command_class=%s, "
"Specific_command_class=%s, "
"Command_class=%s, Value type=%s, "
"Genre=%s", node.node_id,
"Genre=%s as %s", node.node_id,
node.generic, node.specific,
value.command_class, value.type,
value.genre)
name = "{}.{}".format(component, object_id(value))
value.genre, component)
workaround_component = workaround.get_device_component_mapping(
value)
if workaround_component != component:
_LOGGER.debug("Using %s instead of %s",
workaround_component, component)
component = workaround_component

name = "{}.{}".format(component, object_id(value))
node_config = customize.get_overrides(hass, DOMAIN, name)

if node_config.get(CONF_IGNORED):
Expand Down
67 changes: 67 additions & 0 deletions homeassistant/components/zwave/workaround.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Zwave workarounds."""
from . import const

# Manufacturers
FIBARO = 0x010f
PHILIO = 0x013c
WENZHOU = 0x0118

# Product IDs
PHILIO_SLIM_SENSOR = 0x0002
PHILIO_3_IN_1_SENSOR_GEN_4 = 0x000d

# Product Types
FGFS101_FLOOD_SENSOR_TYPE = 0x0b00
PHILIO_SENSOR = 0x0002

# Mapping devices
PHILIO_SLIM_SENSOR_MOTION = (PHILIO, PHILIO_SENSOR, PHILIO_SLIM_SENSOR, 0)
PHILIO_3_IN_1_SENSOR_GEN_4_MOTION = (
PHILIO, PHILIO_SENSOR, PHILIO_3_IN_1_SENSOR_GEN_4, 0)
WENZHOU_SLIM_SENSOR_MOTION = (WENZHOU, PHILIO_SENSOR, PHILIO_SLIM_SENSOR, 0)

# Workarounds
WORKAROUND_NO_OFF_EVENT = 'trigger_no_off_event'

# List of workarounds by (manufacturer_id, product_type, product_id, index)
DEVICE_MAPPINGS = {
PHILIO_SLIM_SENSOR_MOTION: WORKAROUND_NO_OFF_EVENT,
PHILIO_3_IN_1_SENSOR_GEN_4_MOTION: WORKAROUND_NO_OFF_EVENT,
WENZHOU_SLIM_SENSOR_MOTION: WORKAROUND_NO_OFF_EVENT,
}

# Component mapping devices
FIBARO_FGFS101_SENSOR_ALARM = (
FIBARO, FGFS101_FLOOD_SENSOR_TYPE, const.COMMAND_CLASS_SENSOR_ALARM)

# List of component workarounds by
# (manufacturer_id, product_type, command_class)
DEVICE_COMPONENT_MAPPING = {
FIBARO_FGFS101_SENSOR_ALARM: 'binary_sensor',
}


def get_device_component_mapping(value):
"""Get mapping of value to another component."""
if (value.node.manufacturer_id.strip() and
value.node.product_type.strip()):
manufacturer_id = int(value.node.manufacturer_id, 16)
product_type = int(value.node.product_type, 16)
return DEVICE_COMPONENT_MAPPING.get(
(manufacturer_id, product_type, value.command_class))

return None


def get_device_mapping(value):
"""Get mapping of value to a workaround."""
if (value.node.manufacturer_id.strip() and
value.node.product_id.strip() and
value.node.product_type.strip()):
manufacturer_id = int(value.node.manufacturer_id, 16)
product_type = int(value.node.product_type, 16)
product_id = int(value.node.product_id, 16)
return DEVICE_MAPPINGS.get(
(manufacturer_id, product_type, product_id, value.index))

return None

0 comments on commit 1b54218

Please sign in to comment.