From 7127492767744799431d47c0f4a9186239310cd9 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Wed, 11 Mar 2020 08:37:28 -0400 Subject: [PATCH] Additional ZHA cleanup (#32678) * fix double device loading in tests * change imports * None is default --- homeassistant/components/zha/core/gateway.py | 2 +- homeassistant/components/zha/light.py | 4 ++-- homeassistant/components/zha/sensor.py | 4 ++-- tests/components/zha/conftest.py | 1 - tests/components/zha/test_light.py | 22 +++++++++----------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index e2831a55ad4..6c0681d9eca 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -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, diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 3387abf9b87..435f8940032 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -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) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index b5ea7c54072..3953db27f20 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -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 diff --git a/tests/components/zha/conftest.py b/tests/components/zha/conftest.py index 53ffb121291..e6056428db6 100644 --- a/tests/components/zha/conftest.py +++ b/tests/components/zha/conftest.py @@ -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 diff --git a/tests/components/zha/test_light.py b/tests/components/zha/test_light.py index 3a3aff2c653..6f5bd23e297 100644 --- a/tests/components/zha/test_light.py +++ b/tests/components/zha/test_light.py @@ -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",