Skip to content

Commit

Permalink
flashing to homekit
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Jul 20, 2023
1 parent bf9e33e commit 0a0dc78
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vwsfriend/vwsfriend/homekit/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .charging import Charging
from .plug import Plug
from .locking_system import LockingSystem
from .flashing import Flashing

from vwsfriend.__version import __version__

Expand Down Expand Up @@ -166,6 +167,21 @@ def update(self): # noqa: C901
self.accessories[lockingSystemAccessory.aid] = lockingSystemAccessory
configChanged = True

if vehicle.controls.honkAndFlashControl is not None and vehicle.controls.honkAndFlashControl.enabled:
honkAndFlashControl = vehicle.controls.honkAndFlashControl

flashingAccessory = Flashing(driver=self.driver, bridge=self, aid=self.selectAID('Flashing', vin), id='Flashing', vin=vin,
displayName=f'{nickname} Flashing', flashControl=honkAndFlashControl)
flashingAccessory.set_info_service(manufacturer=manufacturer, model=model, serial_number=f'{vin}-flashing')
self.setConfigItem(flashingAccessory.id, flashingAccessory.vin, 'category', flashingAccessory.category)
self.setConfigItem(flashingAccessory.id, flashingAccessory.vin, 'services',
[service.display_name for service in flashingAccessory.services])
if flashingAccessory.aid not in self.accessories:
self.add_accessory(flashingAccessory)
else:
self.accessories[flashingAccessory.aid] = flashingAccessory
configChanged = True

if configChanged:
self.driver.config_changed()
self.persistConfig()
Expand Down
49 changes: 49 additions & 0 deletions vwsfriend/vwsfriend/homekit/flashing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import logging
from threading import Timer

import pyhap

from weconnect.errors import SetterError

from vwsfriend.homekit.genericAccessory import GenericAccessory

LOG = logging.getLogger("VWsFriend")


class Flashing(GenericAccessory):
"""Flashing Accessory"""

category = pyhap.const.CATEGORY_LIGHTBULB

def __init__(self, driver, bridge, aid, id, vin, displayName, flashControl):
super().__init__(driver=driver, bridge=bridge, displayName=displayName, aid=aid, vin=vin, id=id)

self.flashControl = flashControl
self.service = self.add_preload_service('Lightbulb', ['Name', 'ConfiguredName', 'On'])

self.charOn = self.service.configure_char('On', setter_callback=self.__onOnChanged)

self.addNameCharacteristics()

def __onOnChanged(self, value):
if self.flashControl is not None and self.flashControl.enabled:
try:
if value is True:
LOG.info('Start flashing for 10 seconds')
self.flashControl.value = 10

def resetState():
self.charOn.set_value(False)

timer = Timer(10.0, resetState)
timer.start()
else:
LOG.error('Flashing cannot be turned off, please wait for 10 seconds')
except SetterError as setterError:
LOG.error('Error flashing: %s', setterError)
self.charOn.set_value(False)
self.setStatusFault(1, timeout=120)
else:
LOG.error('Flashing cannot be controlled')
self.charOn.set_value(False)
self.setStatusFault(1, timeout=120)

0 comments on commit 0a0dc78

Please sign in to comment.