home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.31k stars 30.62k forks source link

Dyson Sensor test is flaky #23573

Closed awarecan closed 5 years ago

awarecan commented 5 years ago

Home Assistant release with the issue:

dev branch

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Component/platform:

Description of problem:

Dyson sensor test failed on dev branch in CI https://circleci.com/gh/home-assistant/home-assistant/19099

Seems related with PR #22578

cc @etheralm

______________________ test_purecool_update_state[pyloop] ______________________

devices = <MagicMock name='devices' id='140175771946624'>
login = <MagicMock name='login' id='140175771944776'>
hass = <homeassistant.core.HomeAssistant object at 0x7f7d371deda0>

    @asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
    @asynctest.patch('libpurecool.dyson.DysonAccount.devices',
                     return_value=[_get_dyson_purecool_device()])
    async def test_purecool_update_state(devices, login, hass):
        """Test state update."""
        device = devices.return_value[0]
        await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
        await hass.async_block_till_done()
        event = {"msg": "CURRENT-STATE",
                 "product-state": {"fpwr": "OFF", "fdir": "OFF", "auto": "OFF",
                                   "oscs": "ON", "oson": "ON", "nmod": "OFF",
                                   "rhtm": "ON", "fnst": "FAN", "ercd": "11E1",
                                   "wacd": "NONE", "nmdv": "0004", "fnsp": "0002",
                                   "bril": "0002", "corf": "ON", "cflr": "0085",
                                   "hflr": "0095", "sltm": "OFF", "osal": "0045",
                                   "osau": "0095", "ancp": "CUST"}}
        device.state = DysonPureCoolV2State(json.dumps(event))

        callback = device.add_message_listener.call_args_list[3][0][0]
        callback(device.state)
        await hass.async_block_till_done()
        fan_state = hass.states.get("fan.living_room")
        attributes = fan_state.attributes

>       assert fan_state.state == "off"
E       AssertionError: assert 'on' == 'off'
E         - on
E         + off

tests/components/dyson/test_fan.py:689: AssertionError
------------------------------ Captured log call -------------------------------
loader.py                  124 INFO     Loaded dyson from homeassistant.components.dyson
setup.py                   133 INFO     Setting up dyson
__init__.py                 38 INFO     Creating new Dyson component
__init__.py                 57 INFO     Connected to Dyson account
__init__.py                 68 INFO     Connected to device <Mock spec='DysonPureCool' id='140174387630656'>
__init__.py                 94 DEBUG    Starting sensor/fan components
setup.py                   168 INFO     Setup of domain dyson took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=dyson>
loader.py                  124 INFO     Loaded fan from homeassistant.components.fan
loader.py                  124 INFO     Loaded sensor from homeassistant.components.sensor
loader.py                  124 INFO     Loaded vacuum from homeassistant.components.vacuum
loader.py                  124 INFO     Loaded climate from homeassistant.components.climate
loader.py                  124 INFO     Loaded air_quality from homeassistant.components.air_quality
loader.py                  124 INFO     Loaded group from homeassistant.components.group
setup.py                   133 INFO     Setting up sensor
setup.py                   168 INFO     Setup of domain sensor took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=sensor>
core.py                    541 DEBUG    Bus:Handling <Event platform_discovered[L]: discovered=, service=load_platform.sensor, platform=dyson>
setup.py                   133 INFO     Setting up climate
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_away_mode>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_hold_mode>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_aux_heat>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_temperature>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_humidity>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_fan_mode>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_operation_mode>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=set_swing_mode>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=turn_off>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=climate, service=turn_on>
setup.py                   168 INFO     Setup of domain climate took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=climate>
setup.py                   133 INFO     Setting up air_quality
setup.py                   168 INFO     Setup of domain air_quality took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=air_quality>
core.py                    541 DEBUG    Bus:Handling <Event platform_discovered[L]: discovered=, service=load_platform.climate, platform=dyson>
core.py                    541 DEBUG    Bus:Handling <Event platform_discovered[L]: discovered=, service=load_platform.air_quality, platform=dyson>
entity_platform.py         115 INFO     Setting up sensor.dyson
setup.py                   133 INFO     Setting up group
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=group, service=reload>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=group, service=set>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=group, service=remove>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=group, service=set_visibility>
setup.py                   168 INFO     Setup of domain group took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=group>
entity_platform.py         115 INFO     Setting up climate.dyson
entity_platform.py         115 INFO     Setting up air_quality.dyson
setup.py                   133 INFO     Setting up fan
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=turn_on>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=turn_off>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=toggle>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=set_speed>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=oscillate>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=fan, service=set_direction>
setup.py                   168 INFO     Setup of domain fan took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=fan>
setup.py                   133 INFO     Setting up vacuum
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=turn_on>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=turn_off>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=toggle>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=start_pause>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=start>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=pause>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=return_to_base>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=clean_spot>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=locate>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=stop>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=set_fan_speed>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=vacuum, service=send_command>
setup.py                   168 INFO     Setup of domain vacuum took 0.0 seconds.
core.py                    541 DEBUG    Bus:Handling <Event component_loaded[L]: component=vacuum>
core.py                    541 DEBUG    Bus:Handling <Event platform_discovered[L]: discovered=, service=load_platform.fan, platform=dyson>
core.py                    541 DEBUG    Bus:Handling <Event platform_discovered[L]: discovered=, service=load_platform.vacuum, platform=dyson>
entity_platform.py         115 INFO     Setting up fan.dyson
fan.py                      80 DEBUG    Creating new Dyson fans
entity_platform.py         115 INFO     Setting up vacuum.dyson
vacuum.py                   29 DEBUG    Creating new Dyson 360 Eye robot vacuum
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_night_mode>
entity_registry.py         151 INFO     Registered new sensor.dyson entity: sensor.living_room_humidity
core.py                    541 DEBUG    Bus:Handling <Event state_changed[L]: old_state=None, entity_id=sensor.living_room_humidity, new_state=<state sensor.living_room_humidity=<Mock name='mock.environmental_state.humidity' id='140175772378672'>; icon=mdi:water-percent, unit_of_measurement=%, friendly_name=Living room Humidity @ 2019-04-30T18:07:37.057997+00:00>>
entity_registry.py         151 INFO     Registered new sensor.dyson entity: sensor.living_room_temperature
core.py                    541 DEBUG    Bus:Handling <Event state_changed[L]: old_state=None, entity_id=fan.living_room, new_state=<state fan.living_room=on; speed_list=['low', 'medium', 'high'], timer=60, friendly_name=Living room, carbon_filter=80, angle_low=90, night_mode=False, speed=medium, auto_mode=True, flow_direction_front=True, hepa_filter=90, oscillating=True, dyson_speed_list=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], supported_features=3, angle_high=180, dyson_speed=AUTO @ 2019-04-30T18:07:37.059427+00:00>>
entity_registry.py         151 INFO     Registered new air_quality.dyson entity: air_quality.living_room
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_auto_mode>
core.py                    110 ERROR    Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/asyncio/tasks.py", line 240, in _step
    result = coro.send(None)
  File "/home/circleci/repo/homeassistant/helpers/entity_platform.py", line 365, in _async_add_entity
    await entity.async_update_ha_state()
  File "/home/circleci/repo/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    self._async_write_ha_state()
  File "/home/circleci/repo/homeassistant/helpers/entity.py", line 248, in _async_write_ha_state
    state = self.state
  File "/home/circleci/repo/homeassistant/components/dyson/sensor.py", line 175, in state
    return float("{0:.1f}".format(temperature_kelvin - 273.15))
TypeError: unsupported operand type(s) for -: 'Mock' and 'float'
core.py                    110 ERROR    Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/asyncio/tasks.py", line 240, in _step
    result = coro.send(None)
  File "/home/circleci/repo/homeassistant/helpers/entity_platform.py", line 365, in _async_add_entity
    await entity.async_update_ha_state()
  File "/home/circleci/repo/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    self._async_write_ha_state()
  File "/home/circleci/repo/homeassistant/helpers/entity.py", line 248, in _async_write_ha_state
    state = self.state
  File "/home/circleci/repo/homeassistant/components/air_quality/__init__.py", line 143, in state
    return self.particulate_matter_2_5
  File "/home/circleci/repo/homeassistant/components/dyson/air_quality.py", line 88, in particulate_matter_2_5
    return int(self._device.environmental_state.particulate_matter_25)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Mock'
core.py                    541 DEBUG    Bus:Handling <Event call_service[L]: service_data=name=all fans, visible=False, entities=['fan.living_room'], object_id=all_fans, domain=group, service=set>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_angle>
core.py                    541 DEBUG    Bus:Handling <Event state_changed[L]: old_state=None, entity_id=group.all_fans, new_state=<state group.all_fans=on; hidden=True, order=0, entity_id=('fan.living_room',), friendly_name=all fans, auto=True @ 2019-04-30T18:07:37.064090+00:00>>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_flow_direction_front>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_timer>
core.py                    541 DEBUG    Bus:Handling <Event service_registered[L]: domain=dyson, service=set_speed>
air_quality.py              54 DEBUG    air_quality: Message received for Living room device: DysonPureCoolV2State(fan_power=OFF,front_direction=OFF,auto_mode=OFF,oscillation_status=ON,oscillation=ON,night_mode=OFF,continuous_monitoring=ON,fan_state=FAN,night_mode_speed=0004,speed=0002,carbon_filter_state=0085,hepa_filter_state=0095,sleep_timer=OFF,oscillation_angle_low=0045,oscillation_angle_high=0095)

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

Traceback (if applicable):

Additional information:

etheralm commented 5 years ago

yep, I feared that would pop up, but forgot to update it, my bad. I'll add a fix in a sec.

etheralm commented 5 years ago

Done. That pr should fix the issue.