Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def available(self) -> bool:
@property
def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return False
return None

@property
def force_update(self) -> bool:
Expand Down Expand Up @@ -321,7 +321,7 @@ def _attr_setter(self, name, typ, attr, attrs):

value = getattr(self, name)

if not value:
if value is None:
return

try:
Expand Down
6 changes: 3 additions & 3 deletions tests/components/light/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_controlling_state_via_topic(self): \
self.assertIsNone(state.attributes.get('effect'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get('xy_color'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not add assumed state. I guess we should have assumed_state default to return None

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balloob done. The problem is, if a device support assume_state it will be present but on a device without that implement it will not present. I think that is correct.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.


fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
self.hass.block_till_done()
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_brightness_controlling_scale(self):
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

fire_mqtt_message(self.hass, 'test_scale/status', 'on')
self.hass.block_till_done()
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_white_value_controlling_scale(self):
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

fire_mqtt_message(self.hass, 'test_scale/status', 'on')
self.hass.block_till_done()
Expand Down
4 changes: 2 additions & 2 deletions tests/components/light/test_mqtt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_controlling_state_via_topic(self): \
self.assertIsNone(state.attributes.get('effect'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get('xy_color'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

# Turn on the light, full white
fire_mqtt_message(self.hass, 'test_light_rgb',
Expand Down Expand Up @@ -424,7 +424,7 @@ def test_invalid_color_brightness_and_white_values(self): \
self.assertIsNone(state.attributes.get('rgb_color'))
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

# Turn on the light
fire_mqtt_message(self.hass, 'test_light_rgb',
Expand Down
6 changes: 3 additions & 3 deletions tests/components/light/test_mqtt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_state_change_via_topic(self): \
self.assertIsNone(state.attributes.get('brightness'))
self.assertIsNone(state.attributes.get('color_temp'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

fire_mqtt_message(self.hass, 'test_light_rgb', 'on')
self.hass.block_till_done()
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_state_brightness_color_effect_temp_white_change_via_topic(self): \
self.assertIsNone(state.attributes.get('effect'))
self.assertIsNone(state.attributes.get('color_temp'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

# turn on the light, full white
fire_mqtt_message(self.hass, 'test_light_rgb',
Expand Down Expand Up @@ -401,7 +401,7 @@ def test_invalid_values(self): \
self.assertIsNone(state.attributes.get('color_temp'))
self.assertIsNone(state.attributes.get('effect'))
self.assertIsNone(state.attributes.get('white_value'))
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

# turn on the light, full white
fire_mqtt_message(self.hass, 'test_light_rgb',
Expand Down
2 changes: 1 addition & 1 deletion tests/components/light/test_rflink.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_default_setup(hass, monkeypatch):
light_after_first_command = hass.states.get(DOMAIN + '.test')
assert light_after_first_command.state == 'on'
# also after receiving first command state not longer has to be assumed
assert 'assumed_state' not in light_after_first_command.attributes
assert not light_after_first_command.attributes.get('assumed_state')

# mock incoming command event for this device
event_callback({
Expand Down
2 changes: 1 addition & 1 deletion tests/components/lock/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_controlling_state_via_topic(self):

state = self.hass.states.get('lock.test')
self.assertEqual(STATE_UNLOCKED, state.state)
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

fire_mqtt_message(self.hass, 'state-topic', 'LOCK')
self.hass.block_till_done()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/sensor/test_dsmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_default_setup(hass, mock_connection_factory):
# tariff should be translated in human readable and have no unit
power_tariff = hass.states.get('sensor.power_tariff')
assert power_tariff.state == 'low'
assert power_tariff.attributes.get('unit_of_measurement') is None
assert power_tariff.attributes.get('unit_of_measurement') == ''


@asyncio.coroutine
Expand Down
2 changes: 1 addition & 1 deletion tests/components/sensor/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_icon_template(self):
self.hass.block_till_done()

state = self.hass.states.get('sensor.test_template_sensor')
assert 'icon' not in state.attributes
assert state.attributes.get('icon') == ''

self.hass.states.set('sensor.test_state', 'Works')
self.hass.block_till_done()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/switch/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_controlling_state_via_topic(self):

state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

fire_mqtt_message(self.hass, 'state-topic', '1')
self.hass.block_till_done()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/switch/test_rflink.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_default_setup(hass, monkeypatch):
switch_after_first_command = hass.states.get('switch.test')
assert switch_after_first_command.state == 'on'
# also after receiving first command state not longer has to be assumed
assert 'assumed_state' not in switch_after_first_command.attributes
assert not switch_after_first_command.attributes.get('assumed_state')

# mock incoming command event for this device
event_callback({
Expand Down
2 changes: 1 addition & 1 deletion tests/components/switch/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_icon_template(self):
self.hass.block_till_done()

state = self.hass.states.get('switch.test_template_switch')
assert 'icon' not in state.attributes
assert state.attributes.get('icon') == ''

state = self.hass.states.set('switch.test_state', STATE_ON)
self.hass.block_till_done()
Expand Down
4 changes: 2 additions & 2 deletions tests/components/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_set_assumed_state_based_on_tracked(self):
['light.Bowl', 'light.Ceiling', 'sensor.no_exist'])

state = self.hass.states.get(test_group.entity_id)
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

self.hass.states.set('light.Bowl', STATE_ON, {
ATTR_ASSUMED_STATE: True
Expand All @@ -306,7 +306,7 @@ def test_set_assumed_state_based_on_tracked(self):
self.hass.block_till_done()

state = self.hass.states.get(test_group.entity_id)
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

def test_group_updated_after_device_tracker_zone_change(self):
"""Test group state when device tracker in group changes zone."""
Expand Down