diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce0d027..791c8c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v5 with: python-version: ${{ env.DEFAULT_PYTHON }} - name: Install local sunsynk package @@ -66,7 +66,7 @@ jobs: PYTHON: ${{ matrix.python-version }} steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install local sunsynk package @@ -92,7 +92,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ env.DEFAULT_PYTHON }} - name: Install pypa/build diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index ee6f313..f87fcdb 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 - run: npm ci diff --git a/src/ha_addon_sunsynk_multi/a_inverter.py b/src/ha_addon_sunsynk_multi/a_inverter.py index eb7802b..e9e44ba 100644 --- a/src/ha_addon_sunsynk_multi/a_inverter.py +++ b/src/ha_addon_sunsynk_multi/a_inverter.py @@ -6,7 +6,7 @@ from typing import Callable, Iterable, Union import attrs -from mqtt_entity import Device, SensorEntity # type: ignore[import] +from mqtt_entity import Device, Entity, SensorEntity # type: ignore[import] from mqtt_entity.helpers import set_attributes # type: ignore[import] from mqtt_entity.utils import tostr # type: ignore[import] @@ -162,9 +162,14 @@ async def hass_discover_sensors(self) -> bool: manufacturer=OPT.manufacturer, ) - ents = [ - s.create_entity(dev, ist=self) for s in self.ss.values() if not s.hidden - ] + ents: list[Entity] = [] + for s in self.ss.values(): + if s.hidden: + continue + try: + ents.append(s.create_entity(dev, ist=self)) + except Exception as err: # pylint:disable=broad-except + _LOGGER.error("Could not create MQTT entity for %s: %s", s, err) ents.extend(self.create_stats_entities(dev)) await MQTT.connect(OPT) await MQTT.publish_discovery_info(entities=ents) diff --git a/src/ha_addon_sunsynk_multi/a_sensor.py b/src/ha_addon_sunsynk_multi/a_sensor.py index b885be8..34c277d 100644 --- a/src/ha_addon_sunsynk_multi/a_sensor.py +++ b/src/ha_addon_sunsynk_multi/a_sensor.py @@ -185,7 +185,11 @@ async def on_change(val: float | int | str | bool) -> None: return self.entity if isinstance(sensor, (SwitchRWSensor, SwitchRWSensor0)): - self.entity = SwitchEntity(device=dev, **ent, on_change=on_change) + self.entity = SwitchEntity( + device=dev, + **ent, + on_change=on_change, + ) return self.entity if isinstance(sensor, SelectRWSensor): @@ -209,10 +213,11 @@ async def on_change(val: float | int | str | bool) -> None: RWEntity._path = "text" # pylint: disable=protected-access + ent["entity_category"] = "diagnostic" + self.entity = RWEntity( device=dev, **ent, - entity_category="diagnostic", on_change=on_change, ) return self.entity