mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 06:58:14 +00:00
Reworked translation mapping between Characteristic and Exposed values.
- Broke the code out into its own file. - Added chaining and flipped translators to assist with re-using existing translators. Also simplified logic when translating between HomeKit & Z2M values by removing special cases like the "binary" exposes. Since everything can be expressed with translators & translator chains now, the process is streamlined. - Wired up the defaultTranslator during the setup phase, so when mapping is called, there's no nil checks necessary; just a direct call to the mapping.Translator. - Also added more documentation for the translation part since I forgot most of it after a year.
This commit is contained in:
@@ -152,6 +152,7 @@ func TestMappingTranslation(t *testing.T) {
|
||||
&BoolTranslator{
|
||||
characteristic.ContactSensorStateContactDetected,
|
||||
characteristic.ContactSensorStateContactNotDetected}}
|
||||
initExposeMappings(m)
|
||||
|
||||
for _, test := range []struct{ e, c any }{
|
||||
{"CONTACT", characteristic.ContactSensorStateContactDetected},
|
||||
@@ -184,6 +185,7 @@ func TestMappingNumeric(t *testing.T) {
|
||||
|
||||
s := service.NewTemperatureSensor()
|
||||
m := &ExposeMapping{exp, s.CurrentTemperature.C, nil}
|
||||
initExposeMappings(m)
|
||||
|
||||
for _, test := range []struct {
|
||||
v any
|
||||
|
||||
Reference in New Issue
Block a user