* Upgrade pylint to 1.8.1 * Fix no-else-return * Fix bad-whitespace * Fix too-many-nested-blocks * Fix raising-format-tuple See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst * Fix len-as-condition * Fix logging-not-lazy Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string * Fix stop-iteration-return * Fix useless-super-delegation * Fix trailing-comma-tuple Both of these seem to simply be bugs: * Nest: The value of self._humidity never seems to be used anywhere * Dovado: The called API method seems to expect a "normal" number * Fix redefined-argument-from-local * Fix consider-using-enumerate * Fix wrong-import-order * Fix arguments-differ * Fix missed no-else-return * Fix no-member and related * Fix signatures-differ * Revert "Upgrade pylint to 1.8.1" This reverts commit af78aa00f125a7d34add97b9d50c14db48412211. * Fix arguments-differ * except for device_tracker * Cleanup * Fix test using positional argument * Fix line too long I forgot to run flake8 - shame on me... 🙃 * Fix bad-option-value for 1.6.5 * Fix arguments-differ for device_tracker * Upgrade pylint to 1.8.2 * 👕 Fix missed no-member
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""Implements a base class for all IHC devices."""
|
|
import asyncio
|
|
from xml.etree.ElementTree import Element
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
|
class IHCDevice(Entity):
|
|
"""Base class for all ihc devices.
|
|
|
|
All IHC devices have an associated IHC resource. IHCDevice handled the
|
|
registration of the IHC controller callback when the IHC resource changes.
|
|
Derived classes must implement the on_ihc_change method
|
|
"""
|
|
|
|
def __init__(self, ihc_controller, name, ihc_id: int, info: bool,
|
|
product: Element = None) -> None:
|
|
"""Initialize IHC attributes."""
|
|
self.ihc_controller = ihc_controller
|
|
self._name = name
|
|
self.ihc_id = ihc_id
|
|
self.info = info
|
|
if product:
|
|
self.ihc_name = product.attrib['name']
|
|
self.ihc_note = product.attrib['note']
|
|
self.ihc_position = product.attrib['position']
|
|
else:
|
|
self.ihc_name = ''
|
|
self.ihc_note = ''
|
|
self.ihc_position = ''
|
|
|
|
@asyncio.coroutine
|
|
def async_added_to_hass(self):
|
|
"""Add callback for ihc changes."""
|
|
self.ihc_controller.add_notify_event(
|
|
self.ihc_id, self.on_ihc_change, True)
|
|
|
|
@property
|
|
def should_poll(self) -> bool:
|
|
"""No polling needed for ihc devices."""
|
|
return False
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the device name."""
|
|
return self._name
|
|
|
|
@property
|
|
def device_state_attributes(self):
|
|
"""Return the state attributes."""
|
|
if not self.info:
|
|
return {}
|
|
return {
|
|
'ihc_id': self.ihc_id,
|
|
'ihc_name': self.ihc_name,
|
|
'ihc_note': self.ihc_note,
|
|
'ihc_position': self.ihc_position
|
|
}
|
|
|
|
def on_ihc_change(self, ihc_id, value):
|
|
"""Callback when ihc resource changes.
|
|
|
|
Derived classes must overwrite this to do device specific stuff.
|
|
"""
|
|
raise NotImplementedError
|