mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Show new errors from the MotionMount (#137006)
This commit is contained in:
parent
41490dffad
commit
fcb8d25b46
@ -1,6 +1,9 @@
|
||||
"""Support for MotionMount sensors."""
|
||||
|
||||
from typing import Final
|
||||
|
||||
import motionmount
|
||||
from motionmount import MotionMountSystemError
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -9,6 +12,14 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from . import MotionMountConfigEntry
|
||||
from .entity import MotionMountEntity
|
||||
|
||||
ERROR_MESSAGES: Final = {
|
||||
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 +36,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 +56,10 @@ class MotionMountErrorStatusSensor(MotionMountEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> str:
|
||||
"""Return error status."""
|
||||
errors = self.mm.error_status or 0
|
||||
status = self.mm.system_status
|
||||
|
||||
if errors & (1 << 31):
|
||||
# Only when but 31 is set are there any errors active at this moment
|
||||
if errors & (1 << 10):
|
||||
return "motor"
|
||||
|
||||
return "internal"
|
||||
for error, message in ERROR_MESSAGES.items():
|
||||
if error in status:
|
||||
return message
|
||||
|
||||
return "none"
|
||||
|
@ -72,6 +72,9 @@
|
||||
"state": {
|
||||
"none": "None",
|
||||
"motor": "Motor",
|
||||
"hdmi_cec": "HDMI CEC",
|
||||
"obstruction": "Obstruction",
|
||||
"tv_width_constraint": "TV width constraint",
|
||||
"internal": "Internal"
|
||||
}
|
||||
}
|
||||
|
48
tests/components/motionmount/test_sensor.py
Normal file
48
tests/components/motionmount/test_sensor.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""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", "state"),
|
||||
[
|
||||
(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,
|
||||
state: str,
|
||||
) -> None:
|
||||
"""Tests the state attributes."""
|
||||
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 = [system_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
|
Loading…
x
Reference in New Issue
Block a user