Skip to content

Commit cae3d82

Browse files
authored
Merge pull request #5 from extinctCoder/sas-branch-7
feat: add typing, docs deploy workflow, and logger typing
2 parents 4214e49 + 4cb57ad commit cae3d82

6 files changed

Lines changed: 81 additions & 28 deletions

File tree

.github/workflows/docs.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Documentation Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
DeployMkdocs:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout code repository
18+
id: code_checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup python environment
22+
id: setup_python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.13"
26+
27+
- name: Install the required python modules
28+
id: module_installation
29+
run: |
30+
python -m pip install -r requirements.docs.txt
31+
32+
- name: Deploy Documentation on gh-pages branch
33+
id: deploy_mkdocs
34+
run: |
35+
mkdocs gh-deploy --force
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Power Station Simulator
2+
3+
This section contains the Python API documentation for the power station simulation code.
4+
5+
The following modules are documented here:
6+
7+
::: powerstation_simulator.main
8+
9+
::: powerstation_simulator.station_simulator
10+
11+
::: powerstation_simulator.mqtt_client
12+
13+
::: powerstation_simulator.config
14+
15+
::: powerstation_simulator.logger

docs/README.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
# Welcome to MkDocs
1+
# Smart Grid Simulator
22

3-
For full documentation visit [mkdocs.org](https://www.mkdocs.org).
3+
The Smart Grid Simulator is a virtual power station network designed to emulate real-world power generation and distribution. It allows testing and monitoring of smart grid systems without relying on physical hardware.
44

5-
## Commands
5+
## Key Features
6+
- Simulated Power Stations: Generate realistic power output based on configurable parameters.
7+
- Real-Time Data Publishing: Station metadata, output, and status are continuously published via MQTT.
8+
- Configurable & Extensible: Easily set up multiple stations using environment variables or configuration files.
9+
- Monitoring Ready: Data can be visualized through dashboards or consumed by other applications.
610

7-
* `mkdocs new [dir-name]` - Create a new project.
8-
* `mkdocs serve` - Start the live-reloading docs server.
9-
* `mkdocs build` - Build the documentation site.
10-
* `mkdocs -h` - Print help message and exit.
11-
12-
## Project layout
13-
14-
mkdocs.yml # The configuration file.
15-
docs/
16-
index.md # The documentation homepage.
17-
... # Other markdown pages, images and other files.
18-
19-
20-
21-
1. [[mash network|mash_network]]
22-
2. [[current sensor|current sensor]]
23-
3. [[voltage sensor|voltage sensor]]
24-
4.
11+
## Use Cases
12+
- Test smart grid applications safely and efficiently.
13+
- Prototype dashboards and analytics for power monitoring.
14+
- Simulate renewable and conventional energy sources.

mkdocs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
site_name: Smart Grid
2+
repo_url: https://github.com/extinctCoder/smart_grid
3+
edit_uri: https://github.com/extinctCoder/smart_grid/docs
4+
5+
site_author: extinctCoder
6+
site_description: "A smart grid project for efficient energy management."
7+
site_url: https://extinctcoder.github.io/smart_grid
8+
copyright: MIT License
29

310
theme:
411
name: material
12+
font:
13+
text: "Roboto"
14+
code: "Fira Code"
515

616
docs_dir: docs
717
site_dir: site

src/powerstation_simulator/logger.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import sys
3+
from logging import Logger, LogRecord
34

45
COLORS = {
56
"DEBUG": "\033[34m", # BLUE
@@ -22,7 +23,7 @@ class ColoredFormatter(logging.Formatter):
2223
format: Overrides the base Formatter's format method to add colors.
2324
"""
2425

25-
def format(self, record) -> str:
26+
def format(self, record: LogRecord) -> str:
2627
"""
2728
Format the specified record with colored level names.
2829
@@ -38,7 +39,7 @@ def format(self, record) -> str:
3839
return super().format(record)
3940

4041

41-
def setup_base_logger(level=logging.DEBUG):
42+
def setup_base_logger(level: int | str = logging.DEBUG) -> Logger:
4243
"""
4344
Configure and return the root logger with colored output.
4445
@@ -47,11 +48,12 @@ def setup_base_logger(level=logging.DEBUG):
4748
logger already has handlers configured, this function does nothing.
4849
4950
Args:
50-
level: The logging level to set for the root logger.
51-
Default is logging.DEBUG.
51+
level:
52+
The logging level to set for the root logger.
53+
Default is logging.DEBUG.
5254
5355
Returns:
54-
logging.Logger: The configured root logger instance.
56+
Logger: The configured root logger instance.
5557
"""
5658
root_logger = logging.getLogger()
5759
if not root_logger.hasHandlers():
@@ -65,7 +67,7 @@ def setup_base_logger(level=logging.DEBUG):
6567
return root_logger
6668

6769

68-
def getLogger(name: str):
70+
def getLogger(name: str) -> Logger:
6971
"""
7072
Get a logger with the specified name, ensuring the base logger is configured.
7173

src/powerstation_simulator/station_simulator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from random import random
22
from threading import Thread
33
from time import sleep
4+
from typing import Any
45

56
from config import AppConfig
67
from logger import getLogger
@@ -173,7 +174,7 @@ def __publish_output_loop(self):
173174
self.publish_output()
174175
sleep(self.app_config.PUBLISH_INTERVAL_SECONDS)
175176

176-
def __handle_control(self, client, userdata, message):
177+
def __handle_control(self, client: Any, userdata: Any, message: Any):
177178
"""
178179
Callback handler for MQTT control messages.
179180

0 commit comments

Comments
 (0)