Commit Graph

12 Commits

Author SHA1 Message Date
Darell Tan
e9b0e4b0f9 Introduce SetCharacteristicValueFunc to the Mapping
This function allows either replacing or modifying the usual
Exposed->Characteristic value propagation.

It also adds a CurrentValue to the mapping to monitor for
changes/updates, regardless of whether the value was updated into the
Characteristic. This will be the source of truth.
2024-11-24 15:52:40 +08:00
Darell Tan
8d5dc24d7d Use Device.Definition.Vendor as the Manufacturer
This makes more sense for white-label devices, since it shows TuYa
instead of _TZnnn_xxxx and Aqara instead of LUMI.
2024-11-24 15:30:02 +08:00
Darell Tan
d4daef7bce Introduce constructors for ExposeMapping
This should allow the ExposeMapping struct to be changed without
constantly impacting its callers.
2024-11-24 15:25:17 +08:00
Darell Tan
1922f57a6f Added Z2M description to the Accessory name
This should help you better identify devices if you have added some
description in zigbee2mqtt.
2024-11-22 04:31:06 +08:00
Darell Tan
e678f2a31d Only process EndDevices during add and more verbose errors
If a Coordinator is present in the device list, AddDevicesFromJSON will
fail catastrophically, which shouldn't happen. Therefore, make sure only
EndDevices are considered during add. Also updated the tests to check
for this.

Added a device descriptor for failed adds. This will help with
identifying which device failed (and perhaps, why).
2024-11-22 03:40:27 +08:00
Darell Tan
5e24287d8c 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.
2024-11-22 01:27:53 +08:00
Darell Tan
4eac1ba2a9 Fix access check for light expose features
Some dimmers expose features with state|set instead of state|get|set.
Relax the check to cater for more light/dimmers.
2023-08-05 02:17:06 +08:00
Darell Tan
b1949c73fd Handle unknown device types
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.
2023-08-04 23:49:51 +08:00
Darell Tan
3cfc3f68b0 Added debug mode for more verbose logging
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.
2023-08-03 21:32:14 +08:00
Darell Tan
c61da984c9 Add support for dimmers and dimmable bulbs
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.
2023-06-25 02:20:01 +08:00
Darell Tan
ca0b667ea1 Z2M JSON exposes.values could be of numeric type
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.
2023-06-16 22:47:12 +08:00
Darell Tan
84398fc53a "Initial" working version, after cleanup. 2023-04-26 23:20:07 +08:00