kormax / apple-home-key-reader

Apple Home Key Reader Implementation
Apache License 2.0
470 stars 32 forks source link

Different actions for different states #10

Closed ads1230 closed 5 months ago

ads1230 commented 5 months ago

Hi, I'm struggling a bit to get this to work I want to make it so if locked it performs one action and if unlocked another. My current code is below I would appreciate help if anyone could.

    def on_endpoint_authenticated(self, endpoint):
        self._lock_target_state = 0 if self._lock_current_state else 1
        log.info(
            f"Toggling lock state due to endpoint authentication event {self._lock_target_state} -> {self._lock_current_state} {endpoint}"
        )
        self.lock_target_state.set_value(self._lock_target_state, should_notify=True)
        self._lock_current_state = self._lock_target_state
        self.lock_current_state.set_value(self._lock_current_state, should_notify=True)
        if self._lock_current_state == 0:
            requests.post("http://....")
        if self._lock_current_state == 1:
            requests.post("http://....")
kormax commented 5 months ago

I mean, the decision logic looks correct, as for a payload format and request type, that depends on what solution you're trying on hooking up to, and what API it uses.

I'm gonna keep this thread open in case someone can provide a real example for something like Home Assistant.

ads1230 commented 5 months ago

I mean, the decision logic looks correct, as for a payload format and request type, that depends on what solution you're trying on hooking up to, and what API it uses.

I'm gonna keep this thread open in case someone can provide a real example for something like Home Assistant.

Thanks, it's a HA web hook. The web hooks work fine if not in the conditional statements, but when in the statement fail.

ads1230 commented 5 months ago

Ok worked it out. During testing I was using the home app to lock unlock. Seems to work well when phone tapped on reader.