mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
add include and exclude options for generation
This commit is contained in:
@@ -17,6 +17,8 @@ type Config struct {
|
||||
URL string `yaml:"url"`
|
||||
HAAuthToken string `yaml:"ha_auth_token"`
|
||||
HomeZoneEntityId string `yaml:"home_zone_entity_id,omitempty"` // Now optional
|
||||
IncludeDomains []string `yaml:"include_domains,omitempty"` // Optional list of domains to include
|
||||
ExcludeDomains []string `yaml:"exclude_domains,omitempty"` // Optional list of domains to exclude
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
@@ -129,6 +131,35 @@ func generate(config Config) error {
|
||||
}
|
||||
|
||||
domain := parts[0]
|
||||
|
||||
// Filter domains based on include/exclude lists
|
||||
if len(config.IncludeDomains) > 0 {
|
||||
// If include list is specified, only process listed domains
|
||||
found := false
|
||||
for _, includeDomain := range config.IncludeDomains {
|
||||
if domain == includeDomain {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// If only exclude list is specified, skip excluded domains
|
||||
excluded := false
|
||||
for _, excludeDomain := range config.ExcludeDomains {
|
||||
if domain == excludeDomain {
|
||||
println("skipping excluded domain:", domain)
|
||||
excluded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if excluded {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if _, exists := domainMap[domain]; !exists {
|
||||
domainMap[domain] = &Domain{
|
||||
Name: toCamelCase(domain),
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
url: "http://192.168.4.67:8123" # Replace with your Home Assistant URL
|
||||
ha_auth_token: "<token>" # Your auth token or set HA_AUTH_TOKEN env var
|
||||
home_zone_entity_id: "zone.home" # Optional: defaults to zone.home
|
||||
|
||||
# Optional: List of domains to include when generating constants
|
||||
# If provided, only these domains will be processed
|
||||
# Example: ["light", "switch", "climate"]
|
||||
include_domains: []
|
||||
|
||||
# Optional: List of domains to exclude when generating constants
|
||||
# Only used if include_domains is empty
|
||||
# Example: ["device_tracker", "person"]
|
||||
exclude_domains: []
|
||||
|
||||
Reference in New Issue
Block a user