mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Bugfix: Gen-1 Inverter sensor for Indevolt to display "N/A" when turned off (#172559)
This commit is contained in:
@@ -46,6 +46,8 @@ BINARY_SENSORS: Final = (
|
||||
key=IndevoltSystem.HEATING_STATE,
|
||||
generation=(1,),
|
||||
translation_key="electric_heating_state",
|
||||
on_value=1000,
|
||||
off_value=1001,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
|
||||
@@ -939,12 +939,24 @@ class IndevoltSensorEntity(IndevoltEntity, SensorEntity):
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return False when the device is not in the required energy mode."""
|
||||
"""Return False for sensors in a non-applicable state."""
|
||||
|
||||
# Check whether device is not in the required energy mode
|
||||
if self.entity_description.energy_mode is not None:
|
||||
energy_mode = self.coordinator.data.get(IndevoltConfig.READ_ENERGY_MODE)
|
||||
if energy_mode != self.entity_description.energy_mode:
|
||||
return False
|
||||
|
||||
# Check whether inverter is reporting 0 degrees with heater not active (thus reporting to indicate "idle")
|
||||
# Pending fix by Indevolt: https://discord.com/channels/1417471269942591571/1510277757689659522
|
||||
if self.entity_description.key == IndevoltBattery.GEN_1_INVERTER_TEMPERATURE:
|
||||
inverter_temp = self.coordinator.data.get(
|
||||
IndevoltBattery.GEN_1_INVERTER_TEMPERATURE
|
||||
)
|
||||
heating_state = self.coordinator.data.get(IndevoltSystem.HEATING_STATE)
|
||||
if inverter_temp == 0 and heating_state != 1000:
|
||||
return False
|
||||
|
||||
return super().available
|
||||
|
||||
@property
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"6006": 277.16,
|
||||
"6007": 256.39,
|
||||
"7120": 1000,
|
||||
"7121": 1,
|
||||
"7121": 1001,
|
||||
"7600": 35.2,
|
||||
"7605": 28.1,
|
||||
"7620": 27.4,
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor[1][binary_sensor.bk1600_meter_connected-entry]
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
'667': 0,
|
||||
'7101': 5,
|
||||
'7120': 1000,
|
||||
'7121': 1,
|
||||
'7121': 1001,
|
||||
'7600': 35.2,
|
||||
'7605': 28.1,
|
||||
'7620': 27.4,
|
||||
|
||||
@@ -4,7 +4,12 @@ from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from indevolt_api import IndevoltConfig, IndevoltEnergyMode
|
||||
from indevolt_api import (
|
||||
IndevoltBattery,
|
||||
IndevoltConfig,
|
||||
IndevoltEnergyMode,
|
||||
IndevoltSystem,
|
||||
)
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
@@ -115,6 +120,43 @@ async def test_realtime_sensor_energy_mode_availability(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.parametrize("generation", [1], indirect=True)
|
||||
async def test_inverter_sensor_temperature_availability(
|
||||
hass: HomeAssistant,
|
||||
mock_indevolt: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test inverter sensors are only available when temperature is reported."""
|
||||
with patch("homeassistant.components.indevolt.PLATFORMS", [Platform.SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
# Default fixture reports a valid temperature (35.2) with heating off, sensor should be available
|
||||
assert hass.states.get("sensor.bk1600_inverter_temperature").state == "35.2"
|
||||
|
||||
# Set temperature to 0 with heating off - sensor should become unavailable
|
||||
mock_indevolt.fetch_data.return_value[
|
||||
IndevoltBattery.GEN_1_INVERTER_TEMPERATURE
|
||||
] = 0
|
||||
|
||||
freezer.tick(delta=timedelta(seconds=SCAN_INTERVAL))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
hass.states.get("sensor.bk1600_inverter_temperature").state == STATE_UNAVAILABLE
|
||||
)
|
||||
|
||||
# Switch heating on, sensor should be available again with value 0
|
||||
mock_indevolt.fetch_data.return_value[IndevoltSystem.HEATING_STATE] = 1000
|
||||
freezer.tick(delta=timedelta(seconds=SCAN_INTERVAL))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("sensor.bk1600_inverter_temperature").state == "0"
|
||||
|
||||
|
||||
# In individual tests, you can override the mock behavior
|
||||
async def test_battery_pack_filtering(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user