Skip to content

Commit

Permalink
Support for D105 device
Browse files Browse the repository at this point in the history
  • Loading branch information
krasnoukhov committed Apr 18, 2024
1 parent 56b45e5 commit 71c3a96
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The Smart MAIC integration listens for energy data from the device via MQTT prot
Tested with:
* [Розумний лічильник електроенергії c WiFi D101, однофазний, стандартна версія](https://store.smart-maic.com/ua/p684214708-umnyj-schetchik-elektroenergii.html)
* [Розумний лічильник електроенергії c WiFi D103, трифазний, розширена версія](https://store.smart-maic.com/ua/p679987290-umnyj-schetchik-elektroenergii.html)
* [Розумний лічильник імпульсів з WiFi smart-MAIC D105](https://store.smart-maic.com/ua/p811449534-umnyj-schetchik-impulsov.html)

## Highlights

Expand Down
2 changes: 1 addition & 1 deletion custom_components/smart_maic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def name(self) -> str:
"""Return the name of the entity."""
original = super().name
key = self.entity_description.key
suffix = f" {key[-1]}" if key[-1] in ["1", "2", "3"] else ""
suffix = f" {key[-1]}" if key[-1] in ["1", "2", "3", "4", "5"] else ""
return f"{original}{suffix}"
2 changes: 1 addition & 1 deletion custom_components/smart_maic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/krasnoukhov/homeassistant-smart-maic/issues",
"requirements": [],
"version": "1.3.0"
"version": "1.4.0-beta.0"
}
50 changes: 44 additions & 6 deletions custom_components/smart_maic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,49 @@ def phase_descriptions(index="") -> dict[str, SensorEntityDescription]:
}


def point_description(index) -> dict[str, SensorEntityDescription]:
"""Generate entity description for a point"""
return {
f"T{index}": SensorEntityDescription(
key=f"T{index}",
translation_key="point",
state_class=SensorStateClass.MEASUREMENT,
),
}


def channel_description(index) -> dict[str, SensorEntityDescription]:
"""Generate entity description for a channel"""
return {
f"Ch{index}": SensorEntityDescription(
key=f"Ch{index}",
translation_key="channel",
state_class=SensorStateClass.MEASUREMENT,
),
f"TCh{index}": SensorEntityDescription(
key=f"TCh{index}",
translation_key="total_channel",
state_class=SensorStateClass.MEASUREMENT,
),
}


ENTITY_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
# D101
**phase_descriptions(""),
# D103
**phase_descriptions("1"),
**phase_descriptions("2"),
**phase_descriptions("3"),
# D105
**point_description("1"),
**point_description("2"),
**point_description("3"),
**point_description("4"),
**point_description("5"),
**channel_description("1"),
**channel_description("2"),
# Common
"Temp": SensorEntityDescription(
key="Temp",
translation_key="device_temperature",
Expand All @@ -112,7 +150,7 @@ def phase_descriptions(index="") -> dict[str, SensorEntityDescription]:

# NOTE: dict keys here match API response
# But we align "key" values with single phase for consistency
TOTAL_ENTITY_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
PHASE_TOTAL_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
"A": SensorEntityDescription(
key="A",
translation_key="total_current",
Expand Down Expand Up @@ -172,13 +210,13 @@ async def async_setup_entry(
]
)

# NOTE: check if we're dealing with 3-phase device
# NOTE: check if we're dealing with 3-phase device like D103
if coordinator.data.get("A1"):
async_add_entities(
[
SmartMaicTotalSensor(hass, coordinator, entry, description)
for ent in TOTAL_ENTITY_DESCRIPTIONS
if (description := TOTAL_ENTITY_DESCRIPTIONS.get(ent))
SmartMaicPhaseTotalSensor(hass, coordinator, entry, description)
for ent in PHASE_TOTAL_DESCRIPTIONS
if (description := PHASE_TOTAL_DESCRIPTIONS.get(ent))
]
)

Expand All @@ -193,7 +231,7 @@ def native_value(self) -> StateType:
return cast(StateType, value)


class SmartMaicTotalSensor(SmartMaicEntity, SensorEntity):
class SmartMaicPhaseTotalSensor(SmartMaicEntity, SensorEntity):
"""Representation of the Smart MAIC total sensor."""

@property
Expand Down
9 changes: 9 additions & 0 deletions custom_components/smart_maic/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
},
"total_return": {
"name": "Total return"
},
"point": {
"name": "Point"
},
"channel": {
"name": "Channel"
},
"total_channel": {
"name": "Total channel"
}
},
"switch": {
Expand Down

0 comments on commit 71c3a96

Please sign in to comment.