mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix mFi sensors in uninitialized state (#3246)
If mFi sensors are identified but not fully assigned they can have no tag value, and mficlient throws a ValueError to signal this. This patch handles that case by considering such devices to always be STATE_OFF.
This commit is contained in:
committed by
Paulus Schoutsen
parent
9d4ccb1f49
commit
f55095df83
@@ -147,6 +147,11 @@ class TestMfiSensor(unittest.TestCase):
|
||||
self.port.tag = 'balloons'
|
||||
self.assertEqual('balloons', self.sensor.unit_of_measurement)
|
||||
|
||||
def test_uom_uninitialized(self):
|
||||
"""Test that the UOM defaults if not initialized."""
|
||||
type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
|
||||
self.assertEqual('State', self.sensor.unit_of_measurement)
|
||||
|
||||
def test_state_digital(self):
|
||||
"""Test the digital input."""
|
||||
self.port.model = 'Input Digital'
|
||||
@@ -166,6 +171,11 @@ class TestMfiSensor(unittest.TestCase):
|
||||
with mock.patch.dict(mfi.DIGITS, {}):
|
||||
self.assertEqual(1.0, self.sensor.state)
|
||||
|
||||
def test_state_uninitialized(self):
|
||||
"""Test the state of uninitialized sensors."""
|
||||
type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
|
||||
self.assertEqual(mfi.STATE_OFF, self.sensor.state)
|
||||
|
||||
def test_update(self):
|
||||
"""Test the update."""
|
||||
self.sensor.update()
|
||||
|
||||
Reference in New Issue
Block a user