Skip to content

Commit

Permalink
createentity
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Sep 6, 2024
1 parent 73fae9d commit 2ff8cf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/ha_addon_sunsynk_multi/a_inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/ha_addon_sunsynk_multi/a_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 2ff8cf4

Please sign in to comment.