esphome / esphome/issues

Error Using Custom Global Type

Open
#2,831 16 comments 1 reaction 0 assignees View on GitHub
Type: Compile Issue
Dominant language
No language data
Stars
313
Forks
40
PR merge metrics
No merged PRs in 30d

Description

### The problem

When including a header file with a custom class, the global type can't be set to that class.

This is the custom class I currently have in my header file:
```cpp
class CustomTime : public time::RealTimeClock {
public:
void setup() override;
void update() override;
void set_epoch_time(uint32_t epoch) { this->synchronize_epoch_(epoch); }

protected:
time_t time_;
};
```

The error I get is shown below.

### Which version of ESPHome has the issue?

2021.12.1

### What type of installation are you using?

Home Assistant Add-on

### Which version of Home Assistant has the issue?

_No response_

### What platform are you using?

ESP32

### Board

esp32doit-devkit-v1

### Component causing the issue

globals:

### Example YAML snippet

```yaml
globals:
- id: custom_global
type: CustomTime
```

### Anything in the logs that might be useful for us?

```txt
src/main.cpp:125:27: error: 'CustomTime' was not declared in this scope
globals::GlobalsComponent *custom_global;
^
src/main.cpp:125:37: error: template argument 1 is invalid
globals::GlobalsComponent *custom_global;
```

### Additional information

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.