Skip to content

Commit

Permalink
add device info to config
Browse files Browse the repository at this point in the history
  • Loading branch information
jblance committed Jan 10, 2023
1 parent 1b02a15 commit c5022e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
21 changes: 15 additions & 6 deletions mppsolar/outputs/hassd_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def build_msgs(self, *args, **kwargs):
config = get_kwargs(kwargs, "config")
if config is not None:
log.debug(f"config: {config}")
# try for fullconfig
fullconfig = get_kwargs(kwargs, "fullconfig")
# get results topic
# results_topic = config.get("results_topic", None)
# get formatting info
Expand All @@ -39,7 +41,11 @@ def build_msgs(self, *args, **kwargs):
filter = config.get("filter", None)
excl_filter = config.get("excl_filter", None)
tag = config.get("tag", None)
# device_name =
device = fullconfig.get("device", {})
device_name = device.get("name", "mppsolar")
device_id = device.get("id", "mppsolar")
device_model = device.get("model", "mppsolar")
device_manufacturer = device.get("manufacturer", "mppsolar")
else:
# results_topic = None
# get formatting info
Expand All @@ -48,7 +54,10 @@ def build_msgs(self, *args, **kwargs):
filter = get_kwargs(kwargs, "filter")
excl_filter = get_kwargs(kwargs, "excl_filter")
tag = get_kwargs(kwargs, "tag")
device_name = get_kwargs(kwargs, "name", "mppsolar")
device_name = get_kwargs(kwargs, "name", "mppsolar")
device_id = device_name
device_model = device_name
device_manufacturer = "MPP-Solar"

if filter is not None:
filter = re.compile(filter)
Expand Down Expand Up @@ -113,10 +122,10 @@ def build_msgs(self, *args, **kwargs):

# payload["device"] = {"name": f"{device_name}", "identifiers": ["mppsolar"], "model": "PIP6048MAX", "manufacturer": "MPP-Solar"}
payload["device"] = {
"name": f"{device_name}",
"identifiers": [f"{device_name}"],
"model": f"{device_name}",
"manufacturer": "MPP-Solar",
"name": device_name,
"identifiers": [device_id],
"model": device_model,
"manufacturer": device_manufacturer,
}
if unit == "W":
payload.update({"state_class": "measurement", "device_class": "power"})
Expand Down
19 changes: 14 additions & 5 deletions mppsolar/powermon.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def main():
nargs="?",
type=str,
help="Full location of config file",
const="/etc/mpp-solar/powermon.yml",
const="./powermon.yaml",
default=None,
)
parser.add_argument(
Expand All @@ -109,6 +109,12 @@ def main():
parser.add_argument(
"-I", "--info", action="store_true", help="Enable Info and above level messages"
)
parser.add_argument(
"--adhoc",
type=str,
default=None,
help="Send adhoc command to mqtt adhoc command queue - needs config file specified and populated",
)

args = parser.parse_args()
# prog_name = parser.prog
Expand Down Expand Up @@ -151,11 +157,14 @@ def main():
# Build mqtt broker
mqttconfig = config.get("mqttbroker", {})
mqtt_broker = MqttBroker(config=mqttconfig)
# is this just a call to send and adhoc command to the queue?
if args.adhoc:
print("ADHOC is todo")
return
# sub to command topic if defined
if mqtt_broker.enabled:
mqtt_broker.setAdhocCommands(
adhoc_commands=mqttconfig.get("adhoc_commands"), callback=mqtt_callback
)
mqtt_broker.setAdhocCommands(
adhoc_commands=mqttconfig.get("adhoc_commands"), callback=mqtt_callback
)
log.debug(mqtt_broker)

# get port
Expand Down
5 changes: 4 additions & 1 deletion powermon.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
device:
name: Inverter_2
name: Test_Inverter
id: 123456789
model: 8048MAX
manufacturer: MPP-Solar
Expand All @@ -25,7 +25,10 @@ commands:
f_command: f'QED{(date.today()-timedelta(days=1)).strftime("%Y%m%d")}'
outputs:
- name: screen
filter: pv
- name: hassd_mqtt
filter: pv
tag: QED
# - command: QPIRI
# outputs:
# - name: screen
Expand Down

0 comments on commit c5022e1

Please sign in to comment.