Introduce constructors for ExposeMapping

This should allow the ExposeMapping struct to be changed without
constantly impacting its callers.
This commit is contained in:
Darell Tan
2024-11-24 15:25:17 +08:00
parent b11ab07fbb
commit d4daef7bce
8 changed files with 22 additions and 12 deletions

10
z2m.go
View File

@@ -242,6 +242,16 @@ type ExposeMapping struct {
Translator MappingTranslator
}
// Creates a new ExposeMapping
func NewExposeMapping(e *ExposesEntry, c *characteristic.C) *ExposeMapping {
return &ExposeMapping{ExposesEntry: e, Characteristic: c}
}
// Creates a new ExposeMapping with a MappingTranslator
func NewTranslatedExposeMapping(e *ExposesEntry, c *characteristic.C, t MappingTranslator) *ExposeMapping {
return &ExposeMapping{ExposesEntry: e, Characteristic: c, Translator: t}
}
func (m *ExposeMapping) String() string {
return fmt.Sprintf("{%q,%s -> ctyp %s}",
m.ExposesEntry.Name, m.ExposesEntry.Type, m.Characteristic.Type)