Refactor ZHA (#18629)
* refactor ZHA * lint * review request * Exclude more zha modules from coverage
This commit is contained in:
1 parent
cccc41c23e
commit
67aa76d295
12 files changed
+343
-284
No files matched your search
@@ -7,7 +7,8 @@ at https://home-assistant.io/components/switch.zha/
|
||||
import logging
|
||||
|
||||
from homeassistant.components.switch import DOMAIN, SwitchDevice
|
||||
from homeassistant.components import zha
|
||||
from homeassistant.components.zha.entities import ZhaEntity
|
||||
from homeassistant.components.zha import helpers
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -19,7 +20,7 @@ async def async_setup_platform(hass, config, async_add_entities,
|
||||
"""Set up the Zigbee Home Automation switches."""
|
||||
from zigpy.zcl.clusters.general import OnOff
|
||||
|
||||
discovery_info = zha.get_discovery_info(hass, discovery_info)
|
||||
discovery_info = helpers.get_discovery_info(hass, discovery_info)
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
@@ -28,7 +29,7 @@ async def async_setup_platform(hass, config, async_add_entities,
|
||||
if discovery_info['new_join']:
|
||||
in_clusters = discovery_info['in_clusters']
|
||||
cluster = in_clusters[OnOff.cluster_id]
|
||||
await zha.configure_reporting(
|
||||
await helpers.configure_reporting(
|
||||
switch.entity_id, cluster, switch.value_attribute,
|
||||
min_report=0, max_report=600, reportable_change=1
|
||||
)
|
||||
@@ -36,7 +37,7 @@ async def async_setup_platform(hass, config, async_add_entities,
|
||||
async_add_entities([switch], update_before_add=True)
|
||||
|
||||
|
||||
class Switch(zha.Entity, SwitchDevice):
|
||||
class Switch(ZhaEntity, SwitchDevice):
|
||||
"""ZHA switch."""
|
||||
|
||||
_domain = DOMAIN
|
||||
@@ -94,8 +95,8 @@ class Switch(zha.Entity, SwitchDevice):
|
||||
|
||||
async def async_update(self):
|
||||
"""Retrieve latest state."""
|
||||
result = await zha.safe_read(self._endpoint.on_off,
|
||||
['on_off'],
|
||||
allow_cache=False,
|
||||
only_cache=(not self._initialized))
|
||||
result = await helpers.safe_read(self._endpoint.on_off,
|
||||
['on_off'],
|
||||
allow_cache=False,
|
||||
only_cache=(not self._initialized))
|
||||
self._state = result.get('on_off', self._state)
|
||||
Reference in new issue
Block a user