Skip to content

Commit

Permalink
Removed uncaught exceptions from Dyson (home-assistant#34112)
Browse files Browse the repository at this point in the history
* fixed what seems to be a typo

* added load_mock_device in common.py so it loads all the required things into the mocks
so they don't throw exceptions for mocks not being able to convert to int

* reverted change in homeassistant/components/dyson/sensor.py
added both values to the mock device (volatil and volatile)
  • Loading branch information
ziv1234 authored Apr 15, 2020
1 parent 72cc656 commit 5bfc1f3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 94 deletions.
25 changes: 25 additions & 0 deletions tests/components/dyson/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Common utils for Dyson tests."""

from unittest import mock

from libpurecool.dyson_pure_cool import FanSpeed


def load_mock_device(device):
"""Load the mock with default values so it doesn't throw errors."""
device.serial = "XX-XXXXX-XX"
device.name = "Temp Name"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.environmental_state.particulate_matter_25 = "0000"
device.environmental_state.particulate_matter_10 = "0000"
device.environmental_state.nitrogen_dioxide = "0000"
device.environmental_state.volatil_organic_compounds = "0000"
device.environmental_state.volatile_organic_compounds = "0000"
device.environmental_state.temperature = 250
device.state.hepa_filter_state = 0
device.state.carbon_filter_state = 0
device.state.speed = FanSpeed.FAN_SPEED_1.value
device.state.oscillation_angle_low = "000"
device.state.oscillation_angle_high = "000"
device.state.filter_life = "000"
6 changes: 3 additions & 3 deletions tests/components/dyson/test_air_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from homeassistant.helpers import discovery
from homeassistant.setup import async_setup_component

from .common import load_mock_device


def _get_dyson_purecool_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.name = "Living room"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.environmental_state.particulate_matter_25 = "0014"
device.environmental_state.particulate_matter_10 = "0025"
device.environmental_state.nitrogen_dioxide = "0042"
Expand Down
33 changes: 10 additions & 23 deletions tests/components/dyson/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import mock

import asynctest
from libpurecool.const import FocusMode, HeatMode, HeatState, HeatTarget, TiltState
from libpurecool.const import FocusMode, HeatMode, HeatState, HeatTarget
from libpurecool.dyson_pure_hotcool_link import DysonPureHotCoolLink
from libpurecool.dyson_pure_state import DysonPureHotCoolState

Expand All @@ -12,6 +12,8 @@
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.setup import async_setup_component

from .common import load_mock_device

from tests.common import get_test_home_assistant


Expand Down Expand Up @@ -41,7 +43,7 @@ def _get_config():
def _get_device_with_no_state():
"""Return a device with no state."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
load_mock_device(device)
device.state = None
device.environmental_state = None
return device
Expand All @@ -50,66 +52,51 @@ def _get_device_with_no_state():
def _get_device_off():
"""Return a device with state off."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
device.state = mock.Mock()
device.environmental_state = mock.Mock()
load_mock_device(device)
return device


def _get_device_focus():
"""Return a device with fan state of focus mode."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
load_mock_device(device)
device.state.focus_mode = FocusMode.FOCUS_ON.value
return device


def _get_device_diffuse():
"""Return a device with fan state of diffuse mode."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
load_mock_device(device)
device.state.focus_mode = FocusMode.FOCUS_OFF.value
return device


def _get_device_cool():
"""Return a device with state of cooling."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
device.serial = "XX-XXXXX-XX"
device.state.tilt = TiltState.TILT_FALSE.value
load_mock_device(device)
device.state.focus_mode = FocusMode.FOCUS_OFF.value
device.state.heat_target = HeatTarget.celsius(12)
device.state.heat_mode = HeatMode.HEAT_OFF.value
device.state.heat_state = HeatState.HEAT_STATE_OFF.value
device.environmental_state.temperature = 288
device.environmental_state.humidity = 53
return device


def _get_device_heat_off():
"""Return a device with state of heat reached target."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
device.state = mock.Mock()
device.state.tilt = TiltState.TILT_FALSE.value
device.state.focus_mode = FocusMode.FOCUS_ON.value
device.state.heat_target = HeatTarget.celsius(20)
load_mock_device(device)
device.state.heat_mode = HeatMode.HEAT_ON.value
device.state.heat_state = HeatState.HEAT_STATE_OFF.value
device.environmental_state.temperature = 293
device.environmental_state.humidity = 53
return device


def _get_device_heat_on():
"""Return a device with state of heating."""
device = mock.Mock(spec=DysonPureHotCoolLink)
device.name = "Device_name"
load_mock_device(device)
device.serial = "YY-YYYYY-YY"
device.state = mock.Mock()
device.state.tilt = TiltState.TILT_FALSE.value
device.state.focus_mode = FocusMode.FOCUS_ON.value
device.state.heat_target = HeatTarget.celsius(23)
device.state.heat_mode = HeatMode.HEAT_ON.value
device.state.heat_state = HeatState.HEAT_STATE_ON.value
Expand Down
24 changes: 4 additions & 20 deletions tests/components/dyson/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from homeassistant.helpers import discovery
from homeassistant.setup import async_setup_component

from .common import load_mock_device

from tests.common import get_test_home_assistant


Expand All @@ -40,37 +42,19 @@ def __init__(self):
def _get_dyson_purecool_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.name = "Living room"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.state = mock.Mock()
device.state.oscillation = "OION"
device.state.fan_power = "ON"
device.state.speed = FanSpeed.FAN_SPEED_AUTO.value
device.state.night_mode = "OFF"
device.state.auto_mode = "ON"
device.state.oscillation_angle_low = "0090"
device.state.oscillation_angle_high = "0180"
device.state.front_direction = "ON"
device.state.sleep_timer = 60
device.state.hepa_filter_state = "0090"
device.state.carbon_filter_state = "0080"
return device


def _get_dyson_purecoollink_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCoolLink)
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.name = "Living room"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.state = mock.Mock()
device.state.oscillation = "ON"
device.state.fan_mode = "FAN"
device.state.speed = FanSpeed.FAN_SPEED_AUTO.value
device.state.night_mode = "OFF"
return device


Expand Down
8 changes: 5 additions & 3 deletions tests/components/dyson/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from homeassistant.components import dyson

from .common import load_mock_device

from tests.common import get_test_home_assistant


def _get_dyson_account_device_available():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock()
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
return device
Expand All @@ -19,7 +21,7 @@ def _get_dyson_account_device_available():
def _get_dyson_account_device_not_available():
"""Return an invalid device provide by Dyson web services."""
device = mock.Mock()
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.connect = mock.Mock(return_value=False)
device.auto_connect = mock.Mock(return_value=False)
return device
Expand All @@ -28,7 +30,7 @@ def _get_dyson_account_device_not_available():
def _get_dyson_account_device_error():
"""Return an invalid device raising OSError while connecting."""
device = mock.Mock()
device.serial = "XX-XXXXX-XX"
load_mock_device(device)
device.connect = mock.Mock(side_effect=OSError("Network error"))
return device

Expand Down
20 changes: 5 additions & 15 deletions tests/components/dyson/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@
from homeassistant.helpers import discovery
from homeassistant.setup import async_setup_component

from .common import load_mock_device

from tests.common import get_test_home_assistant


def _get_dyson_purecool_device():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
device.serial = "XX-XXXXX-XX"
device.name = "Living room"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.environmental_state.humidity = 42
device.environmental_state.temperature = 280
device.state.hepa_filter_state = 90
device.state.carbon_filter_state = 80
load_mock_device(device)
return device


Expand Down Expand Up @@ -61,10 +56,9 @@ def _get_device_without_state():
def _get_with_state():
"""Return a valid device with state values."""
device = mock.Mock()
load_mock_device(device)
device.name = "Device_name"
device.state = mock.Mock()
device.state.filter_life = 100
device.environmental_state = mock.Mock()
device.environmental_state.dust = 5
device.environmental_state.humidity = 45
device.environmental_state.temperature = 295
Expand All @@ -76,14 +70,10 @@ def _get_with_state():
def _get_with_standby_monitoring():
"""Return a valid device with state but with standby monitoring disable."""
device = mock.Mock()
load_mock_device(device)
device.name = "Device_name"
device.state = mock.Mock()
device.state.filter_life = 100
device.environmental_state = mock.Mock()
device.environmental_state.dust = 5
device.environmental_state.humidity = 0
device.environmental_state.temperature = 0
device.environmental_state.volatil_organic_compounds = 2

return device

Expand Down
30 changes: 0 additions & 30 deletions tests/ignore_uncaught_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
"""List of modules that have uncaught exceptions today. Will be shrunk over time."""
IGNORE_UNCAUGHT_EXCEPTIONS = [
("tests.components.dyson.test_air_quality", "test_purecool_aiq_attributes"),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_update_state"),
(
"tests.components.dyson.test_air_quality",
"test_purecool_component_setup_only_once",
),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_without_discovery"),
(
"tests.components.dyson.test_air_quality",
"test_purecool_aiq_empty_environment_state",
),
(
"tests.components.dyson.test_climate",
"test_setup_component_with_parent_discovery",
),
("tests.components.dyson.test_fan", "test_purecoollink_attributes"),
("tests.components.dyson.test_fan", "test_purecool_turn_on"),
("tests.components.dyson.test_fan", "test_purecool_set_speed"),
("tests.components.dyson.test_fan", "test_purecool_turn_off"),
("tests.components.dyson.test_fan", "test_purecool_set_dyson_speed"),
("tests.components.dyson.test_fan", "test_purecool_oscillate"),
("tests.components.dyson.test_fan", "test_purecool_set_night_mode"),
("tests.components.dyson.test_fan", "test_purecool_set_auto_mode"),
("tests.components.dyson.test_fan", "test_purecool_set_angle"),
("tests.components.dyson.test_fan", "test_purecool_set_flow_direction_front"),
("tests.components.dyson.test_fan", "test_purecool_set_timer"),
("tests.components.dyson.test_fan", "test_purecool_update_state"),
("tests.components.dyson.test_fan", "test_purecool_update_state_filter_inv"),
("tests.components.dyson.test_fan", "test_purecool_component_setup_only_once"),
("tests.components.dyson.test_sensor", "test_purecool_component_setup_only_once"),
("tests.components.ios.test_init", "test_creating_entry_sets_up_sensor"),
("tests.components.ios.test_init", "test_not_configuring_ios_not_creates_entry"),
("tests.components.local_file.test_camera", "test_file_not_readable"),
Expand Down

0 comments on commit 5bfc1f3

Please sign in to comment.