Add sensor platform to MadVR (#121617)

* feat: add sensors

* feat: add tests for sensors

* feat: add options flow

* feat: add tests for options flow

* fix: remove options flow

* fix: remove names and mac sensor, add incoming signal type

* feat: add enum types to supported sensors

* fix: consolidate tests into snapshot

* fix: use consts

* fix: update names and use snapshot platform

* fix: fix test name for new translations

* fix: comment

* fix: improve sensor names

* fix: address comments

* feat: disable uncommon sensors by default

* fix: update sensors

* fix: revert config_flow change
This commit is contained in:
ilan 2024-07-20 23:43:52 -07:00 committed by GitHub
parent 5075f0aac8
commit fcca475e36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 1922 additions and 189 deletions

View File

@ -12,7 +12,7 @@ from homeassistant.core import Event, HomeAssistant, callback
from .coordinator import MadVRCoordinator
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.REMOTE]
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.REMOTE, Platform.SENSOR]
type MadVRConfigEntry = ConfigEntry[MadVRCoordinator]

View File

@ -4,3 +4,31 @@ DOMAIN = "madvr"
DEFAULT_NAME = "envy"
DEFAULT_PORT = 44077
# Sensor keys
TEMP_GPU = "temp_gpu"
TEMP_HDMI = "temp_hdmi"
TEMP_CPU = "temp_cpu"
TEMP_MAINBOARD = "temp_mainboard"
INCOMING_RES = "incoming_res"
INCOMING_SIGNAL_TYPE = "incoming_signal_type"
INCOMING_FRAME_RATE = "incoming_frame_rate"
INCOMING_COLOR_SPACE = "incoming_color_space"
INCOMING_BIT_DEPTH = "incoming_bit_depth"
INCOMING_COLORIMETRY = "incoming_colorimetry"
INCOMING_BLACK_LEVELS = "incoming_black_levels"
INCOMING_ASPECT_RATIO = "incoming_aspect_ratio"
OUTGOING_RES = "outgoing_res"
OUTGOING_SIGNAL_TYPE = "outgoing_signal_type"
OUTGOING_FRAME_RATE = "outgoing_frame_rate"
OUTGOING_COLOR_SPACE = "outgoing_color_space"
OUTGOING_BIT_DEPTH = "outgoing_bit_depth"
OUTGOING_COLORIMETRY = "outgoing_colorimetry"
OUTGOING_BLACK_LEVELS = "outgoing_black_levels"
ASPECT_RES = "aspect_res"
ASPECT_DEC = "aspect_dec"
ASPECT_INT = "aspect_int"
ASPECT_NAME = "aspect_name"
MASKING_RES = "masking_res"
MASKING_DEC = "masking_dec"
MASKING_INT = "masking_int"

View File

@ -25,6 +25,89 @@
"off": "mdi:signal-off"
}
}
},
"sensor": {
"mac_address": {
"default": "mdi:ethernet"
},
"temp_gpu": {
"default": "mdi:thermometer"
},
"temp_hdmi": {
"default": "mdi:thermometer"
},
"temp_cpu": {
"default": "mdi:thermometer"
},
"temp_mainboard": {
"default": "mdi:thermometer"
},
"incoming_res": {
"default": "mdi:television"
},
"incoming_frame_rate": {
"default": "mdi:television"
},
"incoming_color_space": {
"default": "mdi:television"
},
"incoming_bit_depth": {
"default": "mdi:television"
},
"incoming_colorimetry": {
"default": "mdi:television"
},
"incoming_black_levels": {
"default": "mdi:television"
},
"incoming_aspect_ratio": {
"default": "mdi:aspect-ratio"
},
"outgoing_res": {
"default": "mdi:television"
},
"outgoing_frame_rate": {
"default": "mdi:television"
},
"outgoing_color_space": {
"default": "mdi:television"
},
"outgoing_bit_depth": {
"default": "mdi:television"
},
"outgoing_colorimetry": {
"default": "mdi:television"
},
"outgoing_black_levels": {
"default": "mdi:television"
},
"aspect_res": {
"default": "mdi:aspect-ratio"
},
"incoming_signal_type": {
"default": "mdi:video-image"
},
"outgoing_signal_type": {
"default": "mdi:video-image"
},
"aspect_dec": {
"default": "mdi:aspect-ratio"
},
"aspect_int": {
"default": "mdi:aspect-ratio"
},
"aspect_name": {
"default": "mdi:aspect-ratio"
},
"masking_res": {
"default": "mdi:television"
},
"masking_dec": {
"default": "mdi:television"
},
"masking_int": {
"default": "mdi:television"
}
}
}
}

View File

@ -0,0 +1,280 @@
"""Sensor entities for the madVR integration."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import MadVRConfigEntry
from .const import (
ASPECT_DEC,
ASPECT_INT,
ASPECT_NAME,
ASPECT_RES,
INCOMING_ASPECT_RATIO,
INCOMING_BIT_DEPTH,
INCOMING_BLACK_LEVELS,
INCOMING_COLOR_SPACE,
INCOMING_COLORIMETRY,
INCOMING_FRAME_RATE,
INCOMING_RES,
INCOMING_SIGNAL_TYPE,
MASKING_DEC,
MASKING_INT,
MASKING_RES,
OUTGOING_BIT_DEPTH,
OUTGOING_BLACK_LEVELS,
OUTGOING_COLOR_SPACE,
OUTGOING_COLORIMETRY,
OUTGOING_FRAME_RATE,
OUTGOING_RES,
OUTGOING_SIGNAL_TYPE,
TEMP_CPU,
TEMP_GPU,
TEMP_HDMI,
TEMP_MAINBOARD,
)
from .coordinator import MadVRCoordinator
from .entity import MadVREntity
def is_valid_temperature(value: float | None) -> bool:
"""Check if the temperature value is valid."""
return value is not None and value > 0
def get_temperature(coordinator: MadVRCoordinator, key: str) -> float | None:
"""Get temperature value if valid, otherwise return None."""
try:
temp = float(coordinator.data.get(key, 0))
except ValueError:
return None
else:
return temp if is_valid_temperature(temp) else None
@dataclass(frozen=True, kw_only=True)
class MadvrSensorEntityDescription(SensorEntityDescription):
"""Describe madVR sensor entity."""
value_fn: Callable[[MadVRCoordinator], StateType]
SENSORS: tuple[MadvrSensorEntityDescription, ...] = (
MadvrSensorEntityDescription(
key=TEMP_GPU,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_fn=lambda coordinator: get_temperature(coordinator, TEMP_GPU),
translation_key=TEMP_GPU,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=TEMP_HDMI,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_fn=lambda coordinator: get_temperature(coordinator, TEMP_HDMI),
translation_key=TEMP_HDMI,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=TEMP_CPU,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_fn=lambda coordinator: get_temperature(coordinator, TEMP_CPU),
translation_key=TEMP_CPU,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=TEMP_MAINBOARD,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_fn=lambda coordinator: get_temperature(coordinator, TEMP_MAINBOARD),
translation_key=TEMP_MAINBOARD,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=INCOMING_RES,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_RES),
translation_key=INCOMING_RES,
),
MadvrSensorEntityDescription(
key=INCOMING_SIGNAL_TYPE,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_SIGNAL_TYPE),
translation_key=INCOMING_SIGNAL_TYPE,
device_class=SensorDeviceClass.ENUM,
options=["2D", "3D"],
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=INCOMING_FRAME_RATE,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_FRAME_RATE),
translation_key=INCOMING_FRAME_RATE,
),
MadvrSensorEntityDescription(
key=INCOMING_COLOR_SPACE,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_COLOR_SPACE),
translation_key=INCOMING_COLOR_SPACE,
device_class=SensorDeviceClass.ENUM,
options=["RGB", "444", "422", "420"],
),
MadvrSensorEntityDescription(
key=INCOMING_BIT_DEPTH,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_BIT_DEPTH),
translation_key=INCOMING_BIT_DEPTH,
device_class=SensorDeviceClass.ENUM,
options=["8bit", "10bit", "12bit"],
),
MadvrSensorEntityDescription(
key=INCOMING_COLORIMETRY,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_COLORIMETRY),
translation_key=INCOMING_COLORIMETRY,
device_class=SensorDeviceClass.ENUM,
options=["SDR", "HDR10", "HLG 601", "PAL", "709", "DCI", "2020"],
),
MadvrSensorEntityDescription(
key=INCOMING_BLACK_LEVELS,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_BLACK_LEVELS),
translation_key=INCOMING_BLACK_LEVELS,
device_class=SensorDeviceClass.ENUM,
options=["TV", "PC"],
),
MadvrSensorEntityDescription(
key=INCOMING_ASPECT_RATIO,
value_fn=lambda coordinator: coordinator.data.get(INCOMING_ASPECT_RATIO),
translation_key=INCOMING_ASPECT_RATIO,
device_class=SensorDeviceClass.ENUM,
options=["16:9", "4:3"],
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=OUTGOING_RES,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_RES),
translation_key=OUTGOING_RES,
),
MadvrSensorEntityDescription(
key=OUTGOING_SIGNAL_TYPE,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_SIGNAL_TYPE),
translation_key=OUTGOING_SIGNAL_TYPE,
device_class=SensorDeviceClass.ENUM,
options=["2D", "3D"],
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=OUTGOING_FRAME_RATE,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_FRAME_RATE),
translation_key=OUTGOING_FRAME_RATE,
),
MadvrSensorEntityDescription(
key=OUTGOING_COLOR_SPACE,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_COLOR_SPACE),
translation_key=OUTGOING_COLOR_SPACE,
device_class=SensorDeviceClass.ENUM,
options=["RGB", "444", "422", "420"],
),
MadvrSensorEntityDescription(
key=OUTGOING_BIT_DEPTH,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_BIT_DEPTH),
translation_key=OUTGOING_BIT_DEPTH,
device_class=SensorDeviceClass.ENUM,
options=["8bit", "10bit", "12bit"],
),
MadvrSensorEntityDescription(
key=OUTGOING_COLORIMETRY,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_COLORIMETRY),
translation_key=OUTGOING_COLORIMETRY,
device_class=SensorDeviceClass.ENUM,
options=["SDR", "HDR10", "HLG 601", "PAL", "709", "DCI", "2020"],
),
MadvrSensorEntityDescription(
key=OUTGOING_BLACK_LEVELS,
value_fn=lambda coordinator: coordinator.data.get(OUTGOING_BLACK_LEVELS),
translation_key=OUTGOING_BLACK_LEVELS,
device_class=SensorDeviceClass.ENUM,
options=["TV", "PC"],
),
MadvrSensorEntityDescription(
key=ASPECT_RES,
value_fn=lambda coordinator: coordinator.data.get(ASPECT_RES),
translation_key=ASPECT_RES,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=ASPECT_DEC,
value_fn=lambda coordinator: coordinator.data.get(ASPECT_DEC),
translation_key=ASPECT_DEC,
),
MadvrSensorEntityDescription(
key=ASPECT_INT,
value_fn=lambda coordinator: coordinator.data.get(ASPECT_INT),
translation_key=ASPECT_INT,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=ASPECT_NAME,
value_fn=lambda coordinator: coordinator.data.get(ASPECT_NAME),
translation_key=ASPECT_NAME,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=MASKING_RES,
value_fn=lambda coordinator: coordinator.data.get(MASKING_RES),
translation_key=MASKING_RES,
entity_registry_enabled_default=False,
),
MadvrSensorEntityDescription(
key=MASKING_DEC,
value_fn=lambda coordinator: coordinator.data.get(MASKING_DEC),
translation_key=MASKING_DEC,
),
MadvrSensorEntityDescription(
key=MASKING_INT,
value_fn=lambda coordinator: coordinator.data.get(MASKING_INT),
translation_key=MASKING_INT,
entity_registry_enabled_default=False,
),
)
async def async_setup_entry(
hass: HomeAssistant,
entry: MadVRConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the sensor entities."""
coordinator = entry.runtime_data
async_add_entities(MadvrSensor(coordinator, description) for description in SENSORS)
class MadvrSensor(MadVREntity, SensorEntity):
"""Base class for madVR sensors."""
def __init__(
self,
coordinator: MadVRCoordinator,
description: MadvrSensorEntityDescription,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
self.entity_description: MadvrSensorEntityDescription = description
self._attr_unique_id = f"{coordinator.mac}_{description.key}"
@property
def native_value(self) -> float | str | None:
"""Return the state of the sensor."""
return self.entity_description.value_fn(self.coordinator)

View File

@ -36,6 +36,86 @@
"signal_state": {
"name": "Signal state"
}
},
"sensor": {
"temp_gpu": {
"name": "GPU temperature"
},
"temp_hdmi": {
"name": "HDMI temperature"
},
"temp_cpu": {
"name": "CPU temperature"
},
"temp_mainboard": {
"name": "Mainboard temperature"
},
"incoming_res": {
"name": "Incoming resolution"
},
"incoming_signal_type": {
"name": "Incoming signal type"
},
"incoming_frame_rate": {
"name": "Incoming frame rate"
},
"incoming_color_space": {
"name": "Incoming color space"
},
"incoming_bit_depth": {
"name": "Incoming bit depth"
},
"incoming_colorimetry": {
"name": "Incoming colorimetry"
},
"incoming_black_levels": {
"name": "Incoming black levels"
},
"incoming_aspect_ratio": {
"name": "Incoming aspect ratio"
},
"outgoing_res": {
"name": "Outgoing resolution"
},
"outgoing_signal_type": {
"name": "Outgoing signal type"
},
"outgoing_frame_rate": {
"name": "Outgoing frame rate"
},
"outgoing_color_space": {
"name": "Outgoing color space"
},
"outgoing_bit_depth": {
"name": "Outgoing bit depth"
},
"outgoing_colorimetry": {
"name": "Outgoing colorimetry"
},
"outgoing_black_levels": {
"name": "Outgoing black levels"
},
"aspect_res": {
"name": "Aspect resolution"
},
"aspect_dec": {
"name": "Aspect decimal"
},
"aspect_int": {
"name": "Aspect integer"
},
"aspect_name": {
"name": "Aspect name"
},
"masking_res": {
"name": "Masking resolution"
},
"masking_dec": {
"name": "Masking decimal"
},
"masking_int": {
"name": "Masking integer"
}
}
}
}

View File

@ -45,194 +45,6 @@
'state': 'off',
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_hdr_flag-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.madvr_envy_madvr_hdr_flag',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:hdr-off',
'original_name': 'madvr HDR Flag',
'platform': 'madvr',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00:11:22:33:44:55_hdr_flag',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_hdr_flag-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'madVR Envy madvr HDR Flag',
'icon': 'mdi:hdr-off',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.madvr_envy_madvr_hdr_flag',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_outgoing_hdr_flag-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.madvr_envy_madvr_outgoing_hdr_flag',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:hdr-off',
'original_name': 'madvr Outgoing HDR Flag',
'platform': 'madvr',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00:11:22:33:44:55_outgoing_hdr_flag',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_outgoing_hdr_flag-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'madVR Envy madvr Outgoing HDR Flag',
'icon': 'mdi:hdr-off',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.madvr_envy_madvr_outgoing_hdr_flag',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_power_state-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.madvr_envy_madvr_power_state',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:power-off',
'original_name': 'madvr Power State',
'platform': 'madvr',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00:11:22:33:44:55_power_state',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_power_state-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'madVR Envy madvr Power State',
'icon': 'mdi:power-off',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.madvr_envy_madvr_power_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_signal_state-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.madvr_envy_madvr_signal_state',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:signal-off',
'original_name': 'madvr Signal State',
'platform': 'madvr',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00:11:22:33:44:55_signal_state',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_madvr_signal_state-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'madVR Envy madvr Signal State',
'icon': 'mdi:signal-off',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.madvr_envy_madvr_signal_state',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensor_setup[binary_sensor.madvr_envy_outgoing_hdr_flag-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
"""Tests for the MadVR sensor entities."""
from __future__ import annotations
from unittest.mock import AsyncMock, patch
import pytest
from syrupy import SnapshotAssertion
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
import homeassistant.helpers.entity_registry as er
from . import setup_integration
from .conftest import get_update_callback
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensor_setup_and_states(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
mock_madvr_client: AsyncMock,
) -> None:
"""Test setup of the sensor entities and their states."""
with patch("homeassistant.components.madvr.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry)
update_callback = get_update_callback(mock_madvr_client)
# Create a big data update with all sensor values
update_data = {
"temp_gpu": 45.5,
"temp_hdmi": 40.0,
"temp_cpu": 50.2,
"temp_mainboard": 35.8,
"incoming_res": "3840x2160",
"incoming_frame_rate": "60p",
"outgoing_signal_type": "2D",
"incoming_signal_type": "3D",
"incoming_color_space": "RGB",
"incoming_bit_depth": "10bit",
"incoming_colorimetry": "2020",
"incoming_black_levels": "PC",
"incoming_aspect_ratio": "16:9",
"outgoing_res": "3840x2160",
"outgoing_frame_rate": "60p",
"outgoing_color_space": "RGB",
"outgoing_bit_depth": "10bit",
"outgoing_colorimetry": "2020",
"outgoing_black_levels": "PC",
"aspect_res": "3840:2160",
"aspect_dec": "1.78",
"aspect_int": "178",
"aspect_name": "Widescreen",
"masking_res": "3840:2160",
"masking_dec": "1.78",
"masking_int": "178",
}
# Update all sensors at once
update_callback(update_data)
await hass.async_block_till_done()
# Snapshot all entity states
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
# Test invalid temperature value
update_callback({"temp_gpu": -1})
await hass.async_block_till_done()
assert hass.states.get("sensor.madvr_envy_gpu_temperature").state == STATE_UNKNOWN
# Test sensor unknown
update_callback({"incoming_res": None})
await hass.async_block_till_done()
assert (
hass.states.get("sensor.madvr_envy_incoming_resolution").state == STATE_UNKNOWN
)
# Test sensor becomes known again
update_callback({"incoming_res": "1920x1080"})
await hass.async_block_till_done()
assert hass.states.get("sensor.madvr_envy_incoming_resolution").state == "1920x1080"
# Test temperature sensor
update_callback({"temp_gpu": 41.2})
await hass.async_block_till_done()
assert hass.states.get("sensor.madvr_envy_gpu_temperature").state == "41.2"