-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show new errors from the MotionMount #137006
base: dev
Are you sure you want to change the base?
Changes from all commits
0f3e6ef
965424c
d61a9be
a3aa454
a5a07fd
7c47cdf
61d3c72
344d3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
"""Support for MotionMount sensors.""" | ||||||
|
||||||
import motionmount | ||||||
from motionmount import MotionMountSystemError | ||||||
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity | ||||||
from homeassistant.core import HomeAssistant | ||||||
|
@@ -9,6 +10,14 @@ | |||||
from . import MotionMountConfigEntry | ||||||
from .entity import MotionMountEntity | ||||||
|
||||||
error_messages = { | ||||||
MotionMountSystemError.MotorError: "motor", | ||||||
MotionMountSystemError.ObstructionDetected: "obstruction", | ||||||
MotionMountSystemError.TVWidthConstraintError: "tv_width_constraint", | ||||||
MotionMountSystemError.HDMICECError: "hdmi_cec", | ||||||
MotionMountSystemError.InternalError: "internal", | ||||||
} | ||||||
|
||||||
|
||||||
async def async_setup_entry( | ||||||
hass: HomeAssistant, | ||||||
|
@@ -25,7 +34,14 @@ class MotionMountErrorStatusSensor(MotionMountEntity, SensorEntity): | |||||
"""The error status sensor of a MotionMount.""" | ||||||
|
||||||
_attr_device_class = SensorDeviceClass.ENUM | ||||||
_attr_options = ["none", "motor", "internal"] | ||||||
_attr_options = [ | ||||||
"none", | ||||||
"motor", | ||||||
"hdmi_cec", | ||||||
"obstruction", | ||||||
"tv_width_constraint", | ||||||
"internal", | ||||||
] | ||||||
_attr_translation_key = "motionmount_error_status" | ||||||
|
||||||
def __init__( | ||||||
|
@@ -38,13 +54,10 @@ def __init__( | |||||
@property | ||||||
def native_value(self) -> str: | ||||||
"""Return error status.""" | ||||||
errors = self.mm.error_status or 0 | ||||||
|
||||||
if errors & (1 << 31): | ||||||
# Only when but 31 is set are there any errors active at this moment | ||||||
if errors & (1 << 10): | ||||||
return "motor" | ||||||
status = self.mm.system_status | ||||||
|
||||||
return "internal" | ||||||
for error, message in error_messages.items(): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if error in status: | ||||||
return message | ||||||
|
||||||
return "none" |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,49 @@ | ||||||||
"""Tests for the MotionMount Sensor platform.""" | ||||||||
|
||||||||
from unittest.mock import patch | ||||||||
|
||||||||
from motionmount import MotionMountSystemError | ||||||||
import pytest | ||||||||
|
||||||||
from homeassistant.core import HomeAssistant | ||||||||
|
||||||||
from . import ZEROCONF_NAME | ||||||||
|
||||||||
from tests.common import MockConfigEntry | ||||||||
|
||||||||
MAC = bytes.fromhex("c4dd57f8a55f") | ||||||||
|
||||||||
|
||||||||
@pytest.mark.parametrize( | ||||||||
"system_status", | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameterize supports multiple arguments and will split the tuple into the args for you automatically:
Suggested change
|
||||||||
[ | ||||||||
(None, "none"), | ||||||||
(MotionMountSystemError.MotorError, "motor"), | ||||||||
(MotionMountSystemError.ObstructionDetected, "obstruction"), | ||||||||
(MotionMountSystemError.TVWidthConstraintError, "tv_width_constraint"), | ||||||||
(MotionMountSystemError.HDMICECError, "hdmi_cec"), | ||||||||
(MotionMountSystemError.InternalError, "internal"), | ||||||||
], | ||||||||
) | ||||||||
async def test_error_status_sensor_states( | ||||||||
hass: HomeAssistant, | ||||||||
mock_config_entry: MockConfigEntry, | ||||||||
system_status: (MotionMountSystemError, str), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
) -> None: | ||||||||
"""Tests the state attributes.""" | ||||||||
(status, state) = system_status | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
with patch( | ||||||||
"homeassistant.components.motionmount.motionmount.MotionMount", | ||||||||
autospec=True, | ||||||||
) as motionmount_mock: | ||||||||
motionmount_mock.return_value.name = ZEROCONF_NAME | ||||||||
motionmount_mock.return_value.mac = MAC | ||||||||
motionmount_mock.return_value.is_authenticated = True | ||||||||
motionmount_mock.return_value.system_status = [status] | ||||||||
|
||||||||
mock_config_entry.add_to_hass(hass) | ||||||||
|
||||||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id) | ||||||||
|
||||||||
assert hass.states.get("sensor.my_motionmount_error_status").state == state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module-level consts should be all-caps (and optionally denoted as Final):