Additional ZHA cleanup (#32678)

* fix double device loading in tests

* change imports

* None is default
This commit is contained in:
David F. Mulcahey 2020-03-11 08:37:28 -04:00 committed by GitHub
parent 365578d053
commit 7127492767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 18 deletions

View File

@ -235,7 +235,7 @@ class ZHAGateway:
def _send_group_gateway_message(self, zigpy_group, gateway_message_type):
"""Send the gareway event for a zigpy group event."""
zha_group = self._groups.get(zigpy_group.group_id, None)
zha_group = self._groups.get(zigpy_group.group_id)
if zha_group is not None:
async_dispatcher_send(
self._hass,

View File

@ -380,8 +380,8 @@ class Light(ZhaEntity, light.Light):
):
self._color_temp = results["color_temperature"]
color_x = results.get("color_x", None)
color_y = results.get("color_y", None)
color_x = results.get("color_x")
color_y = results.get("color_y")
if color_x is not None and color_y is not None:
self._hs_color = color_util.color_xy_to_hs(
float(color_x / 65535), float(color_y / 65535)

View File

@ -178,10 +178,10 @@ class Battery(Sensor):
state_attrs = {}
attributes = ["battery_size", "battery_quantity"]
results = await self._channel.get_attributes(attributes)
battery_size = results.get("battery_size", None)
battery_size = results.get("battery_size")
if battery_size is not None:
state_attrs["battery_size"] = BATTERY_SIZES.get(battery_size, "Unknown")
battery_quantity = results.get("battery_quantity", None)
battery_quantity = results.get("battery_quantity")
if battery_quantity is not None:
state_attrs["battery_quantity"] = battery_quantity
return state_attrs

View File

@ -157,7 +157,6 @@ def zha_device_restored(hass, zigpy_app_controller, setup_zha):
zigpy_app_controller.devices[zigpy_dev.ieee] = zigpy_dev
await setup_zha()
zha_gateway = hass.data[zha_const.DATA_ZHA][zha_const.DATA_ZHA_GATEWAY]
await zha_gateway.async_load_devices()
return zha_gateway.get_device(zigpy_dev.ieee)
return _zha_device

View File

@ -2,7 +2,7 @@
from datetime import timedelta
from unittest.mock import MagicMock, call, sentinel
import asynctest
from asynctest import CoroutineMock, patch
import pytest
import zigpy.profiles.zha
import zigpy.types
@ -67,9 +67,7 @@ LIGHT_COLOR = {
}
@asynctest.mock.patch(
"zigpy.zcl.clusters.general.OnOff.read_attributes", new=MagicMock()
)
@patch("zigpy.zcl.clusters.general.OnOff.read_attributes", new=MagicMock())
async def test_light_refresh(hass, zigpy_device_mock, zha_device_joined_restored):
"""Test zha light platform refresh."""
@ -107,21 +105,21 @@ async def test_light_refresh(hass, zigpy_device_mock, zha_device_joined_restored
assert hass.states.get(entity_id).state == STATE_OFF
@asynctest.patch(
@patch(
"zigpy.zcl.clusters.lighting.Color.request",
new=asynctest.CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
new=CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
)
@asynctest.patch(
@patch(
"zigpy.zcl.clusters.general.Identify.request",
new=asynctest.CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
new=CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
)
@asynctest.patch(
@patch(
"zigpy.zcl.clusters.general.LevelControl.request",
new=asynctest.CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
new=CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
)
@asynctest.patch(
@patch(
"zigpy.zcl.clusters.general.OnOff.request",
new=asynctest.CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
new=CoroutineMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
)
@pytest.mark.parametrize(
"device, reporting",