Skip to content

Commit

Permalink
hass add device class for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jblance committed Jan 11, 2023
1 parent 05a910d commit 6800f2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
14 changes: 10 additions & 4 deletions mppsolar/outputs/hassd_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def build_msgs(self, *args, **kwargs):
if excl_filter is not None:
excl_filter = re.compile(excl_filter)
if tag is None:
tag = command
if command:
tag = command
else:
tag = "mppsolar"

# Build array of mqtt messages with hass update format
msgs = []
Expand All @@ -77,6 +80,9 @@ def build_msgs(self, *args, **kwargs):
icon = None
if len(data[key]) > 2 and data[key][2] and "icon" in data[key][2]:
icon = data[key][2]["icon"]
device_class = None
if len(data[key]) > 2 and data[key][2] and "device-class" in data[key][2]:
device_class = data[key][2]["device-class"]

# remove spaces
if remove_spaces:
Expand Down Expand Up @@ -121,10 +127,10 @@ def build_msgs(self, *args, **kwargs):
"model": device_model,
"manufacturer": device_manufacturer,
}
if device_class:
payload["device_class"] = device_class
if unit == "W":
payload.update(
{"state_class": "measurement", "device_class": "power"}
)
payload.update({"state_class": "measurement", "device_class": "power"})
if icon:
payload.update({"icon": icon})
# msg = {"topic": topic, "payload": payload, "retain": True}
Expand Down
48 changes: 20 additions & 28 deletions mppsolar/protocols/pi30max.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,23 @@
"type": "QUERY",
"response_type": "INDEXED",
"response": [
[1, "AC Input Voltage", "float", "V", {"icon": "mdi:power-plug"}],
[
1,
"AC Input Voltage",
"float",
"V",
{"icon": "mdi:transmission-tower-export"},
],
[2, "AC Input Frequency", "float", "Hz", {"icon": "mdi:current-ac"}],
[3, "AC Output Voltage", "float", "V", {"icon": "mdi:power-plug"}],
[4, "AC Output Frequency", "float", "Hz", {"icon": "mdi:current-ac"}],
[5, "AC Output Apparent Power", "int", "VA", {"icon": "mdi:power-plug"}],
[5, "AC Output Apparent Power", "int", "VA", {"icon": "mdi:power-plug", "device-class": "apparent_power"}],
[6, "AC Output Active Power", "int", "W", {"icon": "mdi:power-plug"}],
[7, "AC Output Load", "int", "%", {"icon": "mdi:brightness-percent"}],
[8, "BUS Voltage", "int", "V", {"icon": "mdi:details"}],
[9, "Battery Voltage", "float", "V", {"icon": "mdi:battery-outline"}],
[10, "Battery Charging Current", "int", "A", {"icon": "mdi:current-dc"}],
[11, "Battery Capacity", "int", "%", {"icon": "mdi:battery-outline"}],
[11, "Battery Capacity", "int", "%", {"device-class": "battery"}],
[
12,
"Inverter Heat Sink Temperature",
Expand Down Expand Up @@ -263,7 +269,7 @@
"response_type": "INDEXED",
"response": [
[1, "Parallel instance number", "option", ["Not valid", "valid"]],
[2, "Serial number", "bytes:r.decode()", ""],
[2, "Serial number", "bytes:r.decode()", "", {"icon": "mdi:identifier"}],
[
3,
"Work mode",
Expand Down Expand Up @@ -321,12 +327,12 @@
[6, "Grid Frequency", "float", "Hz", {"icon": "mdi:current-ac"}],
[7, "AC Output Voltage", "float", "V", {"icon": "mdi:power-plug"}],
[8, "AC Output Frequency", "float", "Hz", {"icon": "mdi:current-ac"}],
[9, "AC Output Apparent Power", "int", "VA", {"icon": "mdi:power-plug"}],
[9, "AC Output Apparent Power", "int", "VA", {"icon": "mdi:power-plug", "device-class": "apparent_power"}],
[10, "AC Output Active Power", "int", "W", {"icon": "mdi:power-plug"}],
[11, "Load Percentage", "int", "%", {"icon": "mdi:brightness-percent"}],
[12, "Battery Voltage", "float", "V", {"icon": "mdi:battery-outline"}],
[13, "Battery Charging Current", "int", "A", {"icon": "mdi:current-dc"}],
[14, "Battery Capacity", "int", "%", {"icon": "mdi:battery-outline"}],
[14, "Battery Capacity", "int", "%", {"device-class": "battery"}],
[15, "PV1 Input Voltage", "float", "V", {"icon": "mdi:solar-power"}],
[
16,
Expand Down Expand Up @@ -906,9 +912,7 @@
"description": "Enable/disable LED function",
"help": " -- examples: PLEDE0 (disable LED), PLEDE1 (enable LED)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -920,9 +924,7 @@
"description": "Set LED speed",
"help": " -- examples: PLEDS0 (set LED speed low), PLEDS1 (set LED speed medium), PLEDS2 (set LED speed high)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -934,9 +936,7 @@
"description": "Set LED effect",
"help": " -- examples: PLEDM0 (set LED effect breathing), PLEDM2 (set LED effect solid), PLEDM3 (set LED right scrolling)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -948,9 +948,7 @@
"description": "Set LED brightness",
"help": " -- examples: PLEDB1 (set LED brightness low), PLEDB5 (set LED brightness normal), PLEDB9 (set LED brightness high)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -962,9 +960,7 @@
"description": "Set LED total number of colors",
"help": " -- examples: PLEDT2 (set 2 LED colors), PLEDT3 (set 3 LED colors)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -976,9 +972,7 @@
"description": "Set LED color",
"help": " -- examples: PLEDCnRRRGGGBBB (n: 1 line mode, 2 AVR mode, 3 battery mode)",
"type": "SETTER",
"response": [
["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]
],
"response": [["ack", "Command execution", {"NAK": "Failed", "ACK": "Successful"}]],
"test_responses": [
b"(NAK\x73\x73\r",
b"(ACK\x39\x20\r",
Expand All @@ -987,7 +981,7 @@
},
}

COMMANDS_TO_REMOVE = ["Q1", "QID", "QVFW3"]
COMMANDS_TO_REMOVE = ["QID", "QVFW2"]


class pi30max(pi30):
Expand All @@ -1008,6 +1002,4 @@ def __init__(self, *args, **kwargs) -> None:
self.STATUS_COMMANDS = ["QPIGS", "QPIGS2"]
self.SETTINGS_COMMANDS = ["QPIRI", "QFLAG"]
self.DEFAULT_COMMAND = "QPI"
log.info(
f"Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands"
)
log.info(f"Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands")
2 changes: 1 addition & 1 deletion mppsolar/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.15.7"
__version__ = "0.15.8"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mppsolar"
version = "0.15.7"
version = "0.15.8"
#version = "0.05.1"
description = "Package to communicate with Solar inverters and BMSs"
authors = ["John Blance"]
Expand Down

0 comments on commit 6800f2b

Please sign in to comment.