Skip to content

Commit

Permalink
hue_apiv2: Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
msinn committed May 3, 2024
1 parent c202bb0 commit 4b3626c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 49 deletions.
52 changes: 39 additions & 13 deletions hue_apiv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HueApiV2(SmartPlugin):
the update functions for the items
"""

PLUGIN_VERSION = '0.6.5' # (must match the version specified in plugin.yaml)
PLUGIN_VERSION = '0.7.0' # (must match the version specified in plugin.yaml)

hue_sensor_state_values = ['daylight', 'temperature', 'presence', 'lightlevel', 'status']

Expand Down Expand Up @@ -236,16 +236,24 @@ def handle_event(self, event_type, event_item, initialize=False):
self.update_items_from_zigbee_connectivity_event(event_item, initialize)
elif event_item.type.value == 'button':
self.update_button_items_from_event(event_item, initialize=initialize)
elif event_item.type.value == 'device':
self.update_device_items_from_event(event_item, initialize=initialize)
elif event_item.type.value == 'device_power':
self.update_devicepower_items_from_event(event_item, initialize=initialize)
elif event_item.type.value == 'homekit':
self.logger.notice(f"handle_event: 'update': Event-item type '{event_item.type.value}' - status '{event_item.status.value}'")
pass
elif event_item.type.value == 'geofence_client':
pass
elif event_item.type.value == 'entertainment':
pass
elif event_item.type.value == 'scene':
self.logger.notice(f"handle_event: Event-item type '{event_item.type.value}' is unhandled - scene '{event_item.metadata.name}' - event={event_item}")
self.logger.info(f"handle_event: 'update': Event-item type '{event_item.type.value}' is unhandled - scene '{event_item.metadata.name}' - event={event_item}")
pass
else:
self.logger.notice(f"handle_event: Event-item type '{event_item.type.value}' is unhandled - event={event_item}")
self.logger.notice(f"handle_event: 'update': Event-item type '{event_item.type.value}' is unhandled - event={event_item}")
else:
self.logger.notice(f"handle_event: Eventtype {event_type.value} is unhandled")
self.logger.notice(f"handle_event: Eventtype {event_type.value} is unhandled - event={event_item}")
return


Expand Down Expand Up @@ -303,6 +311,7 @@ def update_light_items_from_event(self, event_item, initialize=False):
except:
mirek = 0
self.update_items_with_mapping(event_item, mapping_root, 'ct', mirek, initialize)
self.update_items_with_mapping(event_item, mapping_root, 'alert', event_item.alert.action_values[0].value, initialize)

return

Expand All @@ -311,19 +320,20 @@ def update_group_items_from_event(self, event_item, initialize=False):
if event_item.type.value == 'grouped_light':
mapping_root = event_item.id + mapping_delimiter + 'group' + mapping_delimiter

if self.get_items_for_mapping(mapping_root + 'on') != []:
room = self.v2bridge.groups.grouped_light.get_zone(event_item.id)
name = room.metadata.name
if event_item.id_v1 == '/groups/0':
name = '(All lights)'
self.logger.notice(f"update_group_items_from_event: '{name}' - {event_item}")
# if self.get_items_for_mapping(mapping_root + 'on') != []:
# room = self.v2bridge.groups.grouped_light.get_zone(event_item.id)
# name = room.metadata.name
# if event_item.id_v1 == '/groups/0':
# name = '(All lights)'
# self.logger.notice(f"update_group_items_from_event: '{name}' - {event_item}")

if initialize:
self.update_items_with_mapping(event_item, mapping_root, 'name', self._get_light_name(event_item.id), initialize)
self.update_items_with_mapping(event_item, mapping_root, 'dict', {}, initialize)

self.update_items_with_mapping(event_item, mapping_root, 'on', event_item.on.on, initialize)
self.update_items_with_mapping(event_item, mapping_root, 'bri', event_item.dimming.brightness, initialize)
self.update_items_with_mapping(event_item, mapping_root, 'alert', event_item.alert.action_values[0].value, initialize)

return

Expand Down Expand Up @@ -358,7 +368,7 @@ def update_items_from_zigbee_connectivity_event(self, event_item, initialize=Fal
self.update_items_with_mapping(event_item, mapping_root, 'connectivity', event_item.status.value, initialize)
self.update_items_with_mapping(event_item, mapping_root, 'reachable', str(event_item.status.value) == 'connected', initialize)
else:
self.logger.notice(f"handle_event: '{event_item.type.value}' is unhandled - device '{device_name}', {status=} - event={event_item}")
self.logger.notice(f"update_items_from_zigbee_connectivity_event: '{event_item.type.value}' is unhandled - device '{device_name}', {status=} - event={event_item}")
self.logger.notice(f" - device: {device.product_data.product_archetype.value=} - {device=}")
self.logger.notice(f" - {sensors=}")

Expand All @@ -370,7 +380,7 @@ def update_items_from_zigbee_connectivity_event(self, event_item, initialize=Fal

device_name = self._get_device_name(event_item.owner.rid)
status = event_item.status.value
self.logger.notice(f"handle_event: '{event_item.type.value}' is unhandled - device '{device_name}', {status=} - event={event_item}")
self.logger.notice(f"update_items_from_zigbee_connectivity_event: '{event_item.type.value}' is unhandled - device '{device_name}', {status=} - event={event_item}")
device = self._get_device(event_item.owner.rid)
self.logger.notice(f" - {device=}")
sensors = self.v2bridge.devices.get_sensors(event_item.owner.rid)
Expand Down Expand Up @@ -416,11 +426,26 @@ def update_button_items_from_event(self, event_item, initialize=False):
return


def update_device_items_from_event(self, event_item, initialize=False):

mapping_root = event_item.id + mapping_delimiter + event_item.type.value + mapping_delimiter

if initialize:
# self.logger.notice(f"update_device_items_from_event: {event_item.id=} - {event_item} - {initialize=}")
self.update_items_with_mapping(event_item, mapping_root, 'name', self._get_device_name(event_item.id) )

# self.update_items_with_mapping(event_item, mapping_root, 'power_status', event_item.power_state.battery_state.value, initialize)
# self.update_items_with_mapping(event_item, mapping_root, 'battery_level', event_item.power_state.battery_level, initialize)

return


def update_devicepower_items_from_event(self, event_item, initialize=False):

mapping_root = event_item.id + mapping_delimiter + event_item.type.value + mapping_delimiter

if initialize:
# self.logger.notice(f"update_devicepower_items_from_event: {event_item.owner.rid=} - {event_item}")
self.update_items_with_mapping(event_item, mapping_root, 'name', self._get_device_name(event_item.owner.rid) )

self.update_items_with_mapping(event_item, mapping_root, 'power_status', event_item.power_state.battery_state.value, initialize)
Expand Down Expand Up @@ -448,6 +473,8 @@ def initialize_items_from_bridge(self):
"""
self.logger.debug('initialize_items_from_bridge: Start')
#self.v2bridge.lights.initialize(None)
for event_item in self.v2bridge.devices:
self.update_device_items_from_event(event_item, initialize=True)
for event_item in self.v2bridge.lights:
self.update_light_items_from_event(event_item, initialize=True)
for event_item in self.v2bridge.groups:
Expand Down Expand Up @@ -499,7 +526,6 @@ def parse_item(self, item):

# mapping = config_data['id_v1'] + mapping_delimiter + config_data['resource'] + mapping_delimiter + config_data['function']
mapping = config_data['id'] + mapping_delimiter + config_data['resource'] + mapping_delimiter + config_data['function']

# updating=True, if not read only
if not config_data['function'] in ['reachable', 'battery'] and \
not config_data['function'] in self.hue_sensor_state_values:
Expand Down
58 changes: 22 additions & 36 deletions hue_apiv2/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugin:
# documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1586861-support-thread-für-das-hue2-plugin

version: 0.6.5 # Plugin version (must match the version specified in __init__.py)
version: 0.7.0 # Plugin version (must match the version specified in __init__.py)
sh_minversion: 1.10.0 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
# py_minversion: 3.6 # minimum Python version to use for this plugin
Expand Down Expand Up @@ -73,6 +73,7 @@ item_attributes:
- scene
- sensor
- button
- device
- device_power

hue_apiv2_id:
Expand Down Expand Up @@ -287,26 +288,11 @@ item_structs:
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: bri

ct:
type: num
enforce_updates: True
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: ct

xy:
type: list
enforce_updates: True
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: xy

dict:
type: dict
enforce_updates: True
alert:
type: str
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: dict
hue_apiv2_function@instance: alert


_light_basic:
Expand Down Expand Up @@ -384,23 +370,23 @@ item_structs:
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: connectivity

lighttype:
type: str
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: type

modelid:
type: str
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: modelid

swversion:
type: str
hue_apiv2_resource@instance: ..:.
hue_apiv2_id@instance: ..:.
hue_apiv2_function@instance: swversion
# lighttype:
# type: str
# hue_apiv2_resource@instance: ..:.
# hue_apiv2_id@instance: ..:.
# hue_apiv2_function@instance: type
#
# modelid:
# type: str
# hue_apiv2_resource@instance: ..:.
# hue_apiv2_id@instance: ..:.
# hue_apiv2_function@instance: modelid
#
# swversion:
# type: str
# hue_apiv2_resource@instance: ..:.
# hue_apiv2_id@instance: ..:.
# hue_apiv2_function@instance: swversion



Expand Down

0 comments on commit 4b3626c

Please sign in to comment.