mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Catch ZigBee exceptions when communicating with the devices and log appropriate messages.
This commit is contained in:
parent
c17a4fca80
commit
902077d78b
@ -5,6 +5,7 @@ Contains functionality to use a ZigBee device as a sensor.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from binascii import hexlify
|
||||||
|
|
||||||
from homeassistant.core import JobPriority
|
from homeassistant.core import JobPriority
|
||||||
from homeassistant.const import TEMP_CELCIUS
|
from homeassistant.const import TEMP_CELCIUS
|
||||||
@ -58,7 +59,15 @@ class ZigBeeTemperatureSensor(Entity):
|
|||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
def update(self, *args):
|
def update(self, *args):
|
||||||
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
|
try:
|
||||||
|
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
|
||||||
|
except zigbee.ZIGBEE_TX_FAILURE:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Transmission failure when attempting to get sample from "
|
||||||
|
"ZigBee device at address: %s", hexlify(self._config.address))
|
||||||
|
except zigbee.ZIGBEE_EXCEPTION as exc:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Unable to get sample from ZigBee device: %s", exc)
|
||||||
|
|
||||||
|
|
||||||
# This must be below the classes to which it refers.
|
# This must be below the classes to which it refers.
|
||||||
|
@ -7,7 +7,7 @@ classes.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from binascii import unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
from homeassistant.core import JobPriority
|
from homeassistant.core import JobPriority
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
@ -24,10 +24,12 @@ DEFAULT_DEVICE = "/dev/ttyUSB0"
|
|||||||
DEFAULT_BAUD = 9600
|
DEFAULT_BAUD = 9600
|
||||||
DEFAULT_ADC_MAX_VOLTS = 1.2
|
DEFAULT_ADC_MAX_VOLTS = 1.2
|
||||||
|
|
||||||
# Copied from xbee_helper.const during setup()
|
# Copied from xbee_helper during setup()
|
||||||
GPIO_DIGITAL_OUTPUT_LOW = None
|
GPIO_DIGITAL_OUTPUT_LOW = None
|
||||||
GPIO_DIGITAL_OUTPUT_HIGH = None
|
GPIO_DIGITAL_OUTPUT_HIGH = None
|
||||||
ADC_PERCENTAGE = None
|
ADC_PERCENTAGE = None
|
||||||
|
ZIGBEE_EXCEPTION = None
|
||||||
|
ZIGBEE_TX_FAILURE = None
|
||||||
|
|
||||||
DEVICE = None
|
DEVICE = None
|
||||||
|
|
||||||
@ -43,14 +45,19 @@ def setup(hass, config):
|
|||||||
global GPIO_DIGITAL_OUTPUT_LOW
|
global GPIO_DIGITAL_OUTPUT_LOW
|
||||||
global GPIO_DIGITAL_OUTPUT_HIGH
|
global GPIO_DIGITAL_OUTPUT_HIGH
|
||||||
global ADC_PERCENTAGE
|
global ADC_PERCENTAGE
|
||||||
|
global ZIGBEE_EXCEPTION
|
||||||
|
global ZIGBEE_TX_FAILURE
|
||||||
|
|
||||||
import xbee_helper.const as xb_const
|
import xbee_helper.const as xb_const
|
||||||
from xbee_helper import ZigBee
|
from xbee_helper import ZigBee
|
||||||
|
from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure
|
||||||
from serial import Serial, SerialException
|
from serial import Serial, SerialException
|
||||||
|
|
||||||
GPIO_DIGITAL_OUTPUT_LOW = xb_const.GPIO_DIGITAL_OUTPUT_LOW
|
GPIO_DIGITAL_OUTPUT_LOW = xb_const.GPIO_DIGITAL_OUTPUT_LOW
|
||||||
GPIO_DIGITAL_OUTPUT_HIGH = xb_const.GPIO_DIGITAL_OUTPUT_HIGH
|
GPIO_DIGITAL_OUTPUT_HIGH = xb_const.GPIO_DIGITAL_OUTPUT_HIGH
|
||||||
ADC_PERCENTAGE = xb_const.ADC_PERCENTAGE
|
ADC_PERCENTAGE = xb_const.ADC_PERCENTAGE
|
||||||
|
ZIGBEE_EXCEPTION = ZigBeeException
|
||||||
|
ZIGBEE_TX_FAILURE = ZigBeeTxFailure
|
||||||
|
|
||||||
usb_device = config[DOMAIN].get(CONF_DEVICE, DEFAULT_DEVICE)
|
usb_device = config[DOMAIN].get(CONF_DEVICE, DEFAULT_DEVICE)
|
||||||
baud = int(config[DOMAIN].get(CONF_BAUD, DEFAULT_BAUD))
|
baud = int(config[DOMAIN].get(CONF_BAUD, DEFAULT_BAUD))
|
||||||
@ -222,9 +229,19 @@ class ZigBeeDigitalIn(Entity):
|
|||||||
"""
|
"""
|
||||||
Ask the ZigBee device what its output is set to.
|
Ask the ZigBee device what its output is set to.
|
||||||
"""
|
"""
|
||||||
pin_state = DEVICE.get_gpio_pin(
|
try:
|
||||||
self._config.pin,
|
pin_state = DEVICE.get_gpio_pin(
|
||||||
self._config.address)
|
self._config.pin,
|
||||||
|
self._config.address)
|
||||||
|
except ZIGBEE_TX_FAILURE:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Transmission failure when attempting to get sample from "
|
||||||
|
"ZigBee device at address: %s", hexlify(self._config.address))
|
||||||
|
return
|
||||||
|
except ZIGBEE_EXCEPTION as exc:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Unable to get sample from ZigBee device: %s", exc)
|
||||||
|
return
|
||||||
self._state = self._config.state2bool[pin_state]
|
self._state = self._config.state2bool[pin_state]
|
||||||
|
|
||||||
|
|
||||||
@ -233,10 +250,20 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn):
|
|||||||
Adds functionality to ZigBeeDigitalIn to control an output.
|
Adds functionality to ZigBeeDigitalIn to control an output.
|
||||||
"""
|
"""
|
||||||
def _set_state(self, state):
|
def _set_state(self, state):
|
||||||
DEVICE.set_gpio_pin(
|
try:
|
||||||
self._config.pin,
|
DEVICE.set_gpio_pin(
|
||||||
self._config.bool2state[state],
|
self._config.pin,
|
||||||
self._config.address)
|
self._config.bool2state[state],
|
||||||
|
self._config.address)
|
||||||
|
except ZIGBEE_TX_FAILURE:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Transmission failure when attempting to set output pin on "
|
||||||
|
"ZigBee device at address: %s", hexlify(self._config.address))
|
||||||
|
return
|
||||||
|
except ZIGBEE_EXCEPTION as exc:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Unable to set digital pin on ZigBee device: %s", exc)
|
||||||
|
return
|
||||||
self._state = state
|
self._state = state
|
||||||
if not self.should_poll:
|
if not self.should_poll:
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
@ -281,12 +308,20 @@ class ZigBeeAnalogIn(Entity):
|
|||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
return "%"
|
return "%"
|
||||||
|
|
||||||
def update(self, *args):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
Get the latest reading from the ADC.
|
Get the latest reading from the ADC.
|
||||||
"""
|
"""
|
||||||
self._value = DEVICE.read_analog_pin(
|
try:
|
||||||
self._config.pin,
|
self._value = DEVICE.read_analog_pin(
|
||||||
self._config.max_voltage,
|
self._config.pin,
|
||||||
self._config.address,
|
self._config.max_voltage,
|
||||||
ADC_PERCENTAGE)
|
self._config.address,
|
||||||
|
ADC_PERCENTAGE)
|
||||||
|
except ZIGBEE_TX_FAILURE:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Transmission failure when attempting to get sample from "
|
||||||
|
"ZigBee device at address: %s", hexlify(self._config.address))
|
||||||
|
except ZIGBEE_EXCEPTION as exc:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Unable to get sample from ZigBee device: %s", exc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user