Comments (2)
Thanks Bouke,
This is what I ended up doing to get this working.
in the .GET for characteristics().swift, after the 'responses.append(response) about line 90
} responses.append(response) device.controllerDidGetCharacteristics(channel, forCharacteristic: characteristic) }
in 'Device.swift', I found the 'addSubscriber' func about line 400, duplicated the code and renamed both the 'func' and also the 'delegate?.'
// Add an object which would be notified of changes to Characterisics func controllerDidGetCharacteristics(_ channel: Channel, forCharacteristic characteristic: Characteristic) { subscribersSyncQueue.sync { if !characteristicSubscribers.keys.contains(ObjectIdentifier(characteristic)) { characteristicSubscribers[ObjectIdentifier(characteristic)] = [] } characteristicSubscribers[ObjectIdentifier(characteristic)]!.insert(ObjectIdentifier(channel)) } if let service = characteristic.service, let accessory = service.accessory { delegate?.controllerDidGetCharacteristics(accessory, service: service, characteristic: AnyCharacteristic(characteristic)) } }
in 'DeviceDelegate.swift' I added the following two chunks (near top and about line 80)
public protocol DeviceDelegate: class {
func controllerDidGetCharacteristics(
_ accessory: Accessory,
service: Service,
characteristic: AnyCharacteristic )
public extension DeviceDelegate {
func controllerDidGetCharacteristics(
_ accessory: Accessory,
service: Service,
characteristic: AnyCharacteristic) { }
Finally, back in my 'main.swift' I added the following into the 'DeviceDelegate' class.
class MyDeviceDelegate: DeviceDelegate {
func controllerDidGetCharacteristics(_ accessory: Accessory, service: Service, characteristic: AnyCharacteristic) {
logger.info("Client GET - initiate refresh")
}
This appears to be working - as when the user opens the App, the first thing it does it GET /characteristics which then triggers the DeviceDelegate call, so I can initiate a data refresh.
Kent.
from hap.
This is related to this: #13. It's not necessarily subscribing, but looking up. Currently there's no callback for this, but it might be worth considering to add this. Mind you; you still need to poll your device for status, as you will still be serving stale data initially. For my home, I just poll the device every 30 seconds, which is often enough to not be considered stale.
You could add a callback to characteristics()
endpoint here:
from hap.
Related Issues (20)
- TargetHumidifierDehumidifierState wrong enum HOT 2
- Async get characteristic HOT 5
- valid values HOT 5
- Help using Accessory.Television HOT 1
- Links in README return 404 HOT 1
- How to group accessories ? HOT 2
- Project doesn't run on command line HOT 2
- deprecated warnings when compiling HOT 2
- How to set value of characteristic in a client app? HOT 2
- SecuritySystem - Show as Single Tile HOT 4
- Dynamically add/remove services?
- Characteristic Function not called when updating powerState or brightness of a Accessory.Lightbulb subclass HOT 4
- Getting Illegal instruction on Raspberry Pi4
- Xcode 13 - Package Target Integrity Error HOT 3
- Compatibility with Matter HOT 2
- Adaptive lighting HOT 1
- Cut a new Release?
- When internet drops and comes back, app needs to be restarted. HOT 2
- Are you still working on this package at all? HOT 1
- Not responding accessory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hap.