Skip to content

Commit d354b2e

Browse files
committed
feat: removed comments
1 parent 114337c commit d354b2e

6 files changed

Lines changed: 80 additions & 93 deletions

File tree

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,4 @@ secrets.yaml
101101
AGENTS.md
102102
CLAUDE.md
103103
GEMINI.md
104-
ANTIGRAVITY.md
105-
106-
107-
104+
ANTIGRAVITY.md

AGENTS.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,39 +111,55 @@ done
111111

112112
### Python Style (__init__.py)
113113

114-
#### Formatting
115-
- Indentation: 4 spaces (standard Python)
116-
- Line length: Aim for <= 88 characters (Black style)
117-
- Imports:
118-
- Standard library first
119-
- Third-party (PIL, requests) second
120-
- ESPHome modules last
121-
- Each import grouped and sorted alphabetically within group
122-
- Use `from esphome import ...` for ESPHome imports
114+
#### Formatting & Standards
115+
- **Compliance**: Follow **PEP 8** (code style) and **PEP 257** (docstrings) strictly.
116+
- **Formatter**: Use **Ruff** for linting and automatic formatting.
117+
- **Indentation**: 4 spaces (standard Python).
118+
- **Line length**: Aim for <= 88 characters (standard for Ruff/Black).
119+
- **Strings**: Prefer **f-strings** for string formatting.
120+
- **Imports**:
121+
- Standard library first.
122+
- Third-party (PIL, requests) second.
123+
- ESPHome modules last.
124+
- Each import grouped and sorted alphabetically within group.
125+
- Use `from esphome import ...` for ESPHome imports.
123126

124127
#### Naming
125-
- Variables and functions: `snake_case`
126-
- Constants: `UPPER_SNAKE_CASE`
127-
- Classes: `PascalCase`
128+
- Variables and functions: `snake_case`.
129+
- Constants: `UPPER_SNAKE_CASE` (order list/dict contents alphabetically).
130+
- Classes: `PascalCase`.
128131

129-
#### Error Handling
132+
#### Type Hinting & Docstrings
133+
- **Type Hints**: Use Python type annotations for all function/method signatures to improve clarity and catch bugs.
134+
- **Docstrings**: Use **Google Style** for docstrings. Omit type information in docstrings if already present in the signature.
135+
- **File Headers**: Every file should start with a docstring describing its purpose.
136+
137+
#### Asynchronous Programming
138+
- **Async-First**: ESPHome's integration with Home Assistant relies on non-blocking code.
139+
- Avoid blocking calls (like `time.sleep` or synchronous I/O) in the main loop.
140+
- Use `asyncio` patterns where possible when interacting with external services.
141+
142+
#### Error Handling & Logging
130143
- Use `try`/`except` for specific exceptions:
131144
```python
132145
try:
133146
# operation
134147
except SpecificError as e:
135148
raise core.EsphomeError(f"Context: {e}")
136149
```
137-
- Avoid bare `except:` clauses
138-
- Log warnings with `logging.warning()` for recoverable issues
139-
- Use `logging.info()` for non-error status updates
150+
- Avoid bare `except:` clauses.
151+
- **Logging**:
152+
- Use `_LOGGER.debug`, `_LOGGER.info`, etc.
153+
- Do **not** include the platform or component name in log messages (added automatically).
154+
- Log messages should **not** end with a period.
155+
- Use `logging.warning()` for recoverable issues in Python logic.
140156

141157
#### ESPHome-Specific
142-
- Use `cv.` for config validation (from `esphome.config_validation`)
143-
- Use `cg.` for code generation (from `esphome.codegen`)
144-
- Access config values via `config[CONF_KEY]`
145-
- Use `CORE.relative_config_path(path)` for file paths
146-
- Register triggers with `automation.build_automation()`
158+
- Use `cv.` for config validation (from `esphome.config_validation`).
159+
- Use `cg.` for code generation (from `esphome.codegen`).
160+
- Access config values via `config[CONF_KEY]`.
161+
- Use `CORE.relative_config_path(path)` for file paths.
162+
- Register triggers with `automation.build_automation()`.
147163

148164
## 3. Repository-Specific Practices
149165

components/ehmtxv2/EHMTX.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
#include <string>
2222
#include <regex>
2323

24-
// #define USE_ESP32
25-
// #define EHMTXv2_ADV_BOOT
26-
// #define EHMTXv2_ADV_BOOT_MODE_0
2724

2825
#ifdef USE_ESP32
2926
#ifdef EHMTXv2_ADV_BOOT
@@ -304,7 +301,7 @@ namespace esphome::ehmtx
304301

305302
#ifdef EHMTXv2_LTINDICATOR
306303
/**
307-
* @brief * @brief hides the left top indicator
304+
* @brief hides the left top indicator
308305
*
309306
*/
310307
void EHMTX::hide_ltindicator()
@@ -316,7 +313,7 @@ namespace esphome::ehmtx
316313

317314
#ifdef EHMTXv2_LCINDICATOR
318315
/**
319-
* @brief * @brief hides the left center indicator
316+
* @brief hides the left center indicator
320317
*
321318
*/
322319
void EHMTX::hide_lcindicator()
@@ -328,7 +325,7 @@ namespace esphome::ehmtx
328325

329326
#ifdef EHMTXv2_LBINDICATOR
330327
/**
331-
* @brief * @brief hides the left bottom indicator
328+
* @brief hides the left bottom indicator
332329
*
333330
*/
334331
void EHMTX::hide_lindicator()
@@ -550,7 +547,6 @@ namespace esphome::ehmtx
550547
if (array.size() > 256) {
551548
return;
552549
}
553-
// extract the values
554550
uint16_t i = 0;
555551
for (JsonVariant v : array)
556552
{
@@ -601,7 +597,6 @@ namespace esphome::ehmtx
601597
if (array.size() > 256) {
602598
return;
603599
}
604-
// extract the values
605600
uint16_t i = 0;
606601
for (JsonVariant v : array)
607602
{
@@ -668,7 +663,6 @@ namespace esphome::ehmtx
668663
if (array.size() > 64) {
669664
return;
670665
}
671-
// extract the values
672666
uint16_t i = 0;
673667
for (JsonVariant v : array)
674668
{
@@ -725,7 +719,6 @@ namespace esphome::ehmtx
725719
if (array.size() > 64) {
726720
return;
727721
}
728-
// extract the values
729722
uint16_t i = 0;
730723
for (JsonVariant v : array)
731724
{
@@ -818,7 +811,7 @@ namespace esphome::ehmtx
818811
}
819812
else
820813
{
821-
screen->sbitmap[real_count] = Color(127, 255, icon, 5); // int16_t 32767 = uint8_t(127,255)
814+
screen->sbitmap[real_count] = Color(127, 255, icon, 5);
822815
real_count++;
823816
}
824817
}
@@ -1187,8 +1180,6 @@ namespace esphome::ehmtx
11871180
}
11881181
}
11891182
}
1190-
else
1191-
{
11921183
}
11931184
}
11941185

@@ -1278,9 +1269,6 @@ namespace esphome::ehmtx
12781269
hit = 0;
12791270
ESP_LOGD(TAG, "oldest queue element is first: %d/%d", hit, queue_count);
12801271
}
1281-
else
1282-
{
1283-
// Queue is empty
12841272
}
12851273
this->queue[hit]->status();
12861274

@@ -1491,7 +1479,7 @@ namespace esphome::ehmtx
14911479
}
14921480
#endif
14931481

1494-
// todo nur bei animationen
1482+
14951483
if (this->queue[this->screen_pointer]->mode == MODE_BITMAP_STACK_SCREEN && this->queue[this->screen_pointer]->sbitmap != NULL)
14961484
{
14971485
for (uint8_t i = 0; i < this->queue[this->screen_pointer]->icon; i++)
@@ -1506,7 +1494,7 @@ namespace esphome::ehmtx
15061494
this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0);
15071495
}
15081496
this->next_action_time = this->queue[this->screen_pointer]->last_time + this->queue[this->screen_pointer]->screen_time_;
1509-
// Todo switch for Triggers
1497+
15101498
if (this->queue[this->screen_pointer]->mode == MODE_CLOCK)
15111499
{
15121500
for (auto *t : on_next_clock_triggers_)
@@ -1632,7 +1620,7 @@ namespace esphome::ehmtx
16321620
}
16331621
else
16341622
{
1635-
this->next_action_time = ts + 15000 ; // come back in 15 Seconds
1623+
this->next_action_time = ts + 15000 ;
16361624
for (auto *t : on_empty_queue_triggers_)
16371625
{
16381626
ESP_LOGD(TAG, "on_empty_queue trigger");
@@ -1647,7 +1635,7 @@ namespace esphome::ehmtx
16471635
}
16481636
}
16491637

1650-
// blend handling
1638+
16511639
#ifdef EHMTXv2_BLEND_STEPS
16521640
if ((this->ticks_ <= EHMTXv2_BLEND_STEPS) && (this->brightness_ >= 50) && (this->queue_count() > 1))
16531641
{
@@ -1827,7 +1815,7 @@ namespace esphome::ehmtx
18271815
ESP_LOGI(TAG, "replace_time_date %s", b ? ESPHOME_F("on") : ESPHOME_F("off"));
18281816
}
18291817

1830-
std::string EHMTX::replace_time_date(std::string time_date) // Replace Time Date Strings / Trip5
1818+
std::string EHMTX::replace_time_date(std::string time_date)
18311819
{
18321820
std::string replace_from_string = EHMTXv2_REPLACE_TIME_DATE_FROM;
18331821
std::string replace_to_string = EHMTXv2_REPLACE_TIME_DATE_TO;
@@ -2461,7 +2449,7 @@ namespace esphome::ehmtx
24612449
if (array.size() > 72) {
24622450
return;
24632451
}
2464-
// extract the 24 color values
2452+
24652453
uint8_t red = 0;
24662454
uint8_t gre = 0;
24672455
uint8_t blu = 0;
@@ -2677,7 +2665,7 @@ namespace esphome::ehmtx
26772665
{
26782666
if (this->show_day_of_week)
26792667
{
2680-
auto dow = this->clock->now().day_of_week - 1; // SUN = 0
2668+
auto dow = this->clock->now().day_of_week - 1;
26812669

26822670
Color accent_color = esphome::display::COLOR_OFF;
26832671
if (this->weekday_accent && this->brightness_ < 50)
@@ -2788,7 +2776,7 @@ namespace esphome::ehmtx
27882776
{
27892777
if (output.find("%") != std::string::npos)
27902778
{
2791-
if (this->replace_time_date_active && output == "%p") // check for replace active
2779+
if (this->replace_time_date_active && output == "%p")
27922780
{
27932781
output = this->clock->now().strftime(output);
27942782
output = this->replace_time_date(output);
@@ -2800,7 +2788,7 @@ namespace esphome::ehmtx
28002788
else
28012789
{
28022790
#ifdef EHMTXv2_FLIP_FLOP
2803-
if (output == "%I" && h > 12) // check for 12-hour clock
2791+
if (output == "%I" && h > 12)
28042792
{
28052793
h = h - 12; // Switch to 12-hour clock
28062794
}
@@ -2838,7 +2826,7 @@ namespace esphome::ehmtx
28382826
bool step = false;
28392827
uint8_t y = ystep / EHMTXv2_FLIP_FLOP_SPEED;
28402828

2841-
if (i == 0) // Hours
2829+
if (i == 0)
28422830
{
28432831
if (h != hours)
28442832
{
@@ -2868,7 +2856,7 @@ namespace esphome::ehmtx
28682856
this->display->printf(x, ypos, font, c_, display::TextAlign::BASELINE_LEFT, "%s", parts.at(i).c_str());
28692857
}
28702858
}
2871-
else if (i == 2) // Minutes
2859+
else if (i == 2)
28722860
{
28732861
if (m != minutes)
28742862
{
@@ -2898,7 +2886,7 @@ namespace esphome::ehmtx
28982886
this->display->printf(x, ypos, font, c_, display::TextAlign::BASELINE_LEFT, "%s", parts.at(i).c_str());
28992887
}
29002888
}
2901-
else if (i == 4) // Seconds
2889+
else if (i == 4)
29022890
{
29032891
if (s != seconds)
29042892
{
@@ -2976,7 +2964,7 @@ namespace esphome::ehmtx
29762964
{
29772965
if (output.find("%") != std::string::npos)
29782966
{
2979-
if (this->replace_time_date_active && (output == "%a" || output == "%A" || output == "%b" || output == "%B")) // check for replace active
2967+
if (this->replace_time_date_active && (output == "%a" || output == "%A" || output == "%b" || output == "%B"))
29802968
{
29812969
output = this->clock->now().strftime(output);
29822970
output = this->replace_time_date(output);
@@ -3207,10 +3195,10 @@ namespace esphome::ehmtx
32073195

32083196
int32_t EHMTX::GetTextBounds(esphome::display::BaseFont *font, const char *buffer)
32093197
{
3210-
int x = 0; // A pointer to store the returned x coordinate of the upper left corner in.
3211-
int y = 0; // A pointer to store the returned y coordinate of the upper left corner in.
3212-
int width = 0; // A pointer to store the returned text width in.
3213-
int height = 0; // A pointer to store the returned text height in.
3198+
int x = 0;
3199+
int y = 0;
3200+
int width = 0;
3201+
int height = 0;
32143202
this->display->get_text_bounds(0, 0, buffer, font, esphome::display::TextAlign::TOP_LEFT, &x, &y, &width, &height);
32153203
return width;
32163204
}

components/ehmtxv2/EHMTX.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ namespace esphome::ehmtx
254254
unsigned long last_scroll_time;
255255
unsigned long last_rainbow_time;
256256
unsigned long last_anim_time;
257-
float next_action_time = 0.0; // when is the next screen change
258-
uint32_t tick_next_action = 0; // when is the next screen change
259-
uint32_t ticks_ = 0; // when is the next screen change
257+
float next_action_time = 0.0;
258+
uint32_t tick_next_action = 0;
259+
uint32_t ticks_ = 0;
260260
#ifdef EHMTXv2_USE_VERTICAL_SCROLL
261261
bool vertical_scroll = false;
262262
#endif

components/ehmtxv2/EHMTX_icons.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace esphome::ehmtx
2525
}
2626
else
2727
{
28-
if (this->get_current_frame() == 1) // this->get_animation_frame_count())
28+
if (this->get_current_frame() == 1)
2929
{
3030
this->counting_up = true;
3131
}

0 commit comments

Comments
 (0)