diff --git a/homeassistant/components/asuswrt/bridge.py b/homeassistant/components/asuswrt/bridge.py index 228da7f1a3612..53a0b5d06b54f 100644 --- a/homeassistant/components/asuswrt/bridge.py +++ b/homeassistant/components/asuswrt/bridge.py @@ -41,6 +41,7 @@ SENSORS_LOAD_AVG, SENSORS_RATES, SENSORS_TEMPERATURES, + SENSORS_TEMPERATURES_LEGACY, ) SENSORS_TYPE_BYTES = "sensors_bytes" @@ -277,7 +278,7 @@ async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]: async def _get_available_temperature_sensors(self) -> list[str]: """Check which temperature information is available on the router.""" availability = await self._api.async_find_temperature_commands() - return [SENSORS_TEMPERATURES[i] for i in range(3) if availability[i]] + return [SENSORS_TEMPERATURES_LEGACY[i] for i in range(3) if availability[i]] @handle_errors_and_zip((IndexError, OSError, ValueError), SENSORS_BYTES) async def _get_bytes(self) -> Any: diff --git a/homeassistant/components/asuswrt/const.py b/homeassistant/components/asuswrt/const.py index a4cd6cde94c2a..a60046b50c2a9 100644 --- a/homeassistant/components/asuswrt/const.py +++ b/homeassistant/components/asuswrt/const.py @@ -30,4 +30,5 @@ SENSORS_CONNECTED_DEVICE = ["sensor_connected_device"] SENSORS_LOAD_AVG = ["sensor_load_avg1", "sensor_load_avg5", "sensor_load_avg15"] SENSORS_RATES = ["sensor_rx_rates", "sensor_tx_rates"] -SENSORS_TEMPERATURES = ["2.4GHz", "5.0GHz", "CPU"] +SENSORS_TEMPERATURES_LEGACY = ["2.4GHz", "5.0GHz", "CPU"] +SENSORS_TEMPERATURES = [*SENSORS_TEMPERATURES_LEGACY, "5.0GHz_2", "6.0GHz"] diff --git a/homeassistant/components/asuswrt/sensor.py b/homeassistant/components/asuswrt/sensor.py index 72d99c6081675..f1296befbbad7 100644 --- a/homeassistant/components/asuswrt/sensor.py +++ b/homeassistant/components/asuswrt/sensor.py @@ -156,6 +156,26 @@ class AsusWrtSensorEntityDescription(SensorEntityDescription): entity_registry_enabled_default=False, suggested_display_precision=1, ), + AsusWrtSensorEntityDescription( + key=SENSORS_TEMPERATURES[3], + translation_key="5ghz_2_temperature", + state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + entity_category=EntityCategory.DIAGNOSTIC, + entity_registry_enabled_default=False, + suggested_display_precision=1, + ), + AsusWrtSensorEntityDescription( + key=SENSORS_TEMPERATURES[4], + translation_key="6ghz_temperature", + state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + entity_category=EntityCategory.DIAGNOSTIC, + entity_registry_enabled_default=False, + suggested_display_precision=1, + ), ) diff --git a/homeassistant/components/asuswrt/strings.json b/homeassistant/components/asuswrt/strings.json index 8a3207ec7cb7f..4c8386dcd0042 100644 --- a/homeassistant/components/asuswrt/strings.json +++ b/homeassistant/components/asuswrt/strings.json @@ -82,6 +82,12 @@ }, "cpu_temperature": { "name": "CPU Temperature" + }, + "5ghz_2_temperature": { + "name": "5GHz Temperature (Radio 2)" + }, + "6ghz_temperature": { + "name": "6GHz Temperature" } } }, diff --git a/tests/components/asuswrt/conftest.py b/tests/components/asuswrt/conftest.py index 72cbc37d57167..7710e26707cea 100644 --- a/tests/components/asuswrt/conftest.py +++ b/tests/components/asuswrt/conftest.py @@ -20,8 +20,8 @@ MOCK_CURRENT_TRANSFER_RATES_HTTP = dict(enumerate(MOCK_CURRENT_TRANSFER_RATES)) MOCK_LOAD_AVG_HTTP = {"load_avg_1": 1.1, "load_avg_5": 1.2, "load_avg_15": 1.3} MOCK_LOAD_AVG = list(MOCK_LOAD_AVG_HTTP.values()) -MOCK_TEMPERATURES_HTTP = {"2.4GHz": 40.2, "CPU": 71.2} -MOCK_TEMPERATURES = {**MOCK_TEMPERATURES_HTTP, "5.0GHz": 0} +MOCK_TEMPERATURES = {"2.4GHz": 40.2, "5.0GHz": 0, "CPU": 71.2} +MOCK_TEMPERATURES_HTTP = {**MOCK_TEMPERATURES, "5.0GHz_2": 40.3, "6.0GHz": 40.4} @pytest.fixture(name="patch_setup_entry") @@ -118,9 +118,9 @@ def mock_controller_connect_http(mock_devices_http): MOCK_CURRENT_TRANSFER_RATES_HTTP ) service_mock.return_value.async_get_loadavg.return_value = MOCK_LOAD_AVG_HTTP - service_mock.return_value.async_get_temperatures.return_value = ( - MOCK_TEMPERATURES_HTTP - ) + service_mock.return_value.async_get_temperatures.return_value = { + k: v for k, v in MOCK_TEMPERATURES_HTTP.items() if k != "5.0GHz" + } yield service_mock @@ -140,6 +140,6 @@ def mock_controller_connect_http_sens_detect(): """Mock a successful sensor detection using http library.""" with patch( f"{ASUSWRT_BASE}.bridge.AsusWrtHttpBridge._get_available_temperature_sensors", - return_value=[*MOCK_TEMPERATURES], + return_value=[*MOCK_TEMPERATURES_HTTP], ) as mock_sens_detect: yield mock_sens_detect diff --git a/tests/components/asuswrt/test_sensor.py b/tests/components/asuswrt/test_sensor.py index a7b19bb378505..e3122f1dfef36 100644 --- a/tests/components/asuswrt/test_sensor.py +++ b/tests/components/asuswrt/test_sensor.py @@ -12,6 +12,7 @@ SENSORS_LOAD_AVG, SENSORS_RATES, SENSORS_TEMPERATURES, + SENSORS_TEMPERATURES_LEGACY, ) from homeassistant.components.device_tracker import CONF_CONSIDER_HOME from homeassistant.config_entries import ConfigEntryState @@ -39,7 +40,7 @@ SENSORS_DEFAULT = [*SENSORS_BYTES, *SENSORS_RATES] -SENSORS_ALL_LEGACY = [*SENSORS_DEFAULT, *SENSORS_LOAD_AVG, *SENSORS_TEMPERATURES] +SENSORS_ALL_LEGACY = [*SENSORS_DEFAULT, *SENSORS_LOAD_AVG, *SENSORS_TEMPERATURES_LEGACY] SENSORS_ALL_HTTP = [*SENSORS_DEFAULT, *SENSORS_LOAD_AVG, *SENSORS_TEMPERATURES] @@ -242,11 +243,13 @@ async def test_temperature_sensors_http_fail( assert not hass.states.get(f"{sensor_prefix}_2_4ghz") assert not hass.states.get(f"{sensor_prefix}_5_0ghz") assert not hass.states.get(f"{sensor_prefix}_cpu") + assert not hass.states.get(f"{sensor_prefix}_5_0ghz_2") + assert not hass.states.get(f"{sensor_prefix}_6_0ghz") -async def _test_temperature_sensors(hass: HomeAssistant, config) -> None: +async def _test_temperature_sensors(hass: HomeAssistant, config, sensors) -> str: """Test creating a AsusWRT temperature sensors.""" - config_entry, sensor_prefix = _setup_entry(hass, config, SENSORS_TEMPERATURES) + config_entry, sensor_prefix = _setup_entry(hass, config, sensors) config_entry.add_to_hass(hass) # initial devices setup @@ -255,20 +258,31 @@ async def _test_temperature_sensors(hass: HomeAssistant, config) -> None: async_fire_time_changed(hass, utcnow() + timedelta(seconds=30)) await hass.async_block_till_done() - # assert temperature sensor available - assert hass.states.get(f"{sensor_prefix}_2_4ghz").state == "40.2" - assert not hass.states.get(f"{sensor_prefix}_5_0ghz") - assert hass.states.get(f"{sensor_prefix}_cpu").state == "71.2" + return sensor_prefix async def test_temperature_sensors_legacy(hass: HomeAssistant, connect_legacy) -> None: """Test creating a AsusWRT temperature sensors.""" - await _test_temperature_sensors(hass, CONFIG_DATA_TELNET) + sensor_prefix = await _test_temperature_sensors( + hass, CONFIG_DATA_TELNET, SENSORS_TEMPERATURES_LEGACY + ) + # assert temperature sensor available + assert hass.states.get(f"{sensor_prefix}_2_4ghz").state == "40.2" + assert hass.states.get(f"{sensor_prefix}_cpu").state == "71.2" + assert not hass.states.get(f"{sensor_prefix}_5_0ghz") async def test_temperature_sensors_http(hass: HomeAssistant, connect_http) -> None: """Test creating a AsusWRT temperature sensors.""" - await _test_temperature_sensors(hass, CONFIG_DATA_HTTP) + sensor_prefix = await _test_temperature_sensors( + hass, CONFIG_DATA_HTTP, SENSORS_TEMPERATURES + ) + # assert temperature sensor available + assert hass.states.get(f"{sensor_prefix}_2_4ghz").state == "40.2" + assert hass.states.get(f"{sensor_prefix}_cpu").state == "71.2" + assert hass.states.get(f"{sensor_prefix}_5_0ghz_2").state == "40.3" + assert hass.states.get(f"{sensor_prefix}_6_0ghz").state == "40.4" + assert not hass.states.get(f"{sensor_prefix}_5_0ghz") @pytest.mark.parametrize( @@ -416,7 +430,7 @@ async def test_decorator_errors( hass: HomeAssistant, connect_legacy, mock_available_temps ) -> None: """Test AsusWRT sensors are unavailable on decorator type check error.""" - sensors = [*SENSORS_BYTES, *SENSORS_TEMPERATURES] + sensors = [*SENSORS_BYTES, *SENSORS_TEMPERATURES_LEGACY] config_entry, sensor_prefix = _setup_entry(hass, CONFIG_DATA_TELNET, sensors) config_entry.add_to_hass(hass)