- 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.
For devices that we have no idea how to handle, i.e. no services or
expose entries were processed, we return ErrUnknownDeviceType and skip
it during AddDevicesFromJSON(). This prevents a device from showing up
where HomeKit says it's not supported.
Also had to rename the existing DEBUG consts to DEVMODE, so as to not
confuse the two. DEVMODE is meant for developers and cannot be enabled
on-the-fly, whereas debug mode is for users to check that the bridge is
working, MQTT messages are received etc.
Update logging is throttled to avoid spurious messages for uncoalesced
MQTT updates and motion sensors. On my network with 10 devices, an
update is logged every 1-2 minutes on average.
The exposes entry looks similar to a switch, except the type is a
"light" and it has `state` and `brightness`. Tested only on single
channel dimmers.
Also added a PercentageTranslator to translate between the HomeKit
`brightness`, which is a percentage, to/from an arbitrary numeric value
in Z2M.
encoding/json would refuse to implicitly cast the numbers into strings.
Currently we don't use these values, so let's preserve their type using
`any` for now.
An example is `keep_time` for occupancy sensors, where it's
[30, 60, 120] seconds.