Skip to content

Commit 78af4b1

Browse files
committed
Linting
1 parent 10a3516 commit 78af4b1

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ run apk add --no-cache --virtual .build-deps gcc g++ make libffi-dev openssl-dev
44

55
copy ["./dist/*.whl", "/modbus4mqtt/"]
66

7+
copy ["./modbus4mqtt/config", "/modbus4mqtt/config/"]
8+
79
run pip install /modbus4mqtt/*.whl
810

911
run apk del .build-deps
1012

13+
run rm /modbus4mqtt/*.whl
14+
1115
entrypoint ["modbus4mqtt"]

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
rm -r dist
44
uv build .
5-
docker build -t tjhowse/modbus4mqtt:1.0.0-rc1 .
5+
docker build -t tjhowse/modbus4mqtt:1.0.0-rc2 .

modbus4mqtt/modbus4mqtt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _set_mqtt_connection_status(self, status: MqttConnectionStatus):
317317
def _on_message(self, client, userdata, msg):
318318
# print("got a message: {}: {}".format(msg.topic, msg.payload))
319319
# TODO Handle json_key writes. https://github.com/tjhowse/modbus4mqtt/issues/23
320-
topic = msg.topic[len(self.prefix) :]
320+
topic = msg.topic[len(self.prefix):]
321321
for register in [
322322
register for register in self.registers if "set_topic" in register
323323
]:
@@ -424,9 +424,15 @@ def _validate_registers(registers):
424424
)
425425
)
426426

427-
def _load_modbus_config(self, path):
427+
def _load_modbus_config(self, path: str) -> dict:
428428
yaml = YAML(typ="safe")
429-
result = yaml.load(open(path, "r").read())
429+
try:
430+
result = yaml.load(open(path, "r").read())
431+
except FileNotFoundError:
432+
# Try to load the config from the pre-1.0.0 location. I.E. replace "config" with "modbus4mqtt"
433+
alt_path = path.replace("config", "modbus4mqtt")
434+
logging.warning("Failed to find config file on path: {}. Checking alternative path {}".format(path, alt_path))
435+
result = yaml.load(open(alt_path, "r").read())
430436
registers = [
431437
register for register in result["registers"] if "pub_topic" in register
432438
]

tests/test_modbus_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ async def test_mqtt_write(
308308
else:
309309
assert False, "Timeout waiting for Modbus register to update"
310310

311+
311312
if __name__ == "__main__":
312313
# Just run a modbus server
313314
modbus_server = ModbusServer()

0 commit comments

Comments
 (0)