Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tests/test_mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def test_publish_status_success(self, mock_client_class, mqtt_client, temp_db):
# Verify payload structure
message = json.loads(payload)
assert "total_time" in message
assert "date" in message
assert "timestamp" in message
assert "last_mqtt_message" in message
assert "total_time_last_check" in message
assert message["total_time"] == 3600.0

@patch("workpulse.mqtt_client.mqtt.Client")
Expand Down Expand Up @@ -260,9 +260,11 @@ def test_publish_status_with_last_update(
assert result is True
call_args = mock_client.publish.call_args
payload = json.loads(call_args[0][1])
assert "last_update" in payload
assert "total_time_last_check" in payload
# last_update should be a string (ISO format) or None
assert payload["last_update"] is None or isinstance(payload["last_update"], str)
assert payload["total_time_last_check"] is None or isinstance(
payload["total_time_last_check"], str
)

@patch("workpulse.mqtt_client.mqtt.Client")
def test_publish_status_exception(self, mock_client_class, mqtt_client):
Expand Down
5 changes: 2 additions & 3 deletions workpulse/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ def publish_status(self) -> bool:
# Prepare message payload
timestamp = datetime.now()
message = {
"last_update": (
"total_time_last_check": (
today_log.last_update.isoformat() if today_log.last_update else None
),
"total_time": today_log.total_active_time,
"timestamp": timestamp.isoformat(),
"date": today_log.date.isoformat(),
"last_mqtt_message": timestamp.isoformat(),
}

# Convert to JSON
Expand Down