Philips Hue

Python implementation

Philips Hue bridge communication driver

class hat.drivers.hue.LightAlert(value)

Bases: enum.Enum

An enumeration.

NONE = 'none'
SELECT = 'select'
LSELECT = 'lselect'
class hat.drivers.hue.LightEffect(value)

Bases: enum.Enum

An enumeration.

NONE = 'none'
COLOR_LOOP = 'colorloop'
class hat.drivers.hue.DeviceType(value)

Bases: enum.Enum

An enumeration.

LIGHT = 'lights'
SENSOR = 'sensors'
class hat.drivers.hue.DeviceId(type, label)

Bases: tuple

Create new instance of DeviceId(type, label)

Parameters
  • type (hat.drivers.hue.common.DeviceType) –

  • label (str) –

type: hat.drivers.hue.common.DeviceType

Alias for field number 0

label: str

Alias for field number 1

class hat.drivers.hue.LightState(on=None, bri=None, alert=None, reachable=None, hue=None, sat=None, effect=None)

Bases: tuple

Light state

Parameters
  • on (Optional[bool]) –

  • bri (Optional[int]) –

  • alert (Optional[hat.drivers.hue.common.LightAlert]) –

  • reachable (Optional[bool]) –

  • hue (Optional[int]) –

  • sat (Optional[int]) –

  • effect (Optional[hat.drivers.hue.common.LightEffect]) –

on

on/off state

bri

brightness between 1 (min) and 254 (max)

alert

light alert state

reachable

is device reachable

hue

hue between 0 and 65535

sat

saturnation between 0 (white) and 254 (colored)

effect

light effect

Create new instance of LightState(on, bri, alert, reachable, hue, sat, effect)

on: Optional[bool]

Alias for field number 0

bri: Optional[int]

Alias for field number 1

alert: Optional[hat.drivers.hue.common.LightAlert]

Alias for field number 2

reachable: Optional[bool]

Alias for field number 3

hue: Optional[int]

Alias for field number 4

sat: Optional[int]

Alias for field number 5

effect: Optional[hat.drivers.hue.common.LightEffect]

Alias for field number 6

class hat.drivers.hue.SensorState(last_updated=None)

Bases: tuple

Sensor state

Parameters

last_updated (Optional[datetime.datetime]) –

last_updated

last updated time

Create new instance of SensorState(last_updated,)

last_updated: Optional[datetime.datetime]

Alias for field number 0

class hat.drivers.hue.Device(id, subtype, name, model_id, manufacturer_name, sw_version, unique_id, state)

Bases: tuple

Create new instance of Device(id, subtype, name, model_id, manufacturer_name, sw_version, unique_id, state)

Parameters
  • id (hat.drivers.hue.common.DeviceId) –

  • subtype (str) –

  • name (str) –

  • model_id (str) –

  • manufacturer_name (str) –

  • sw_version (str) –

  • unique_id (Optional[str]) –

  • state (Union[hat.drivers.hue.common.LightState, hat.drivers.hue.common.SensorState]) –

id: hat.drivers.hue.common.DeviceId

Alias for field number 0

subtype: str

Alias for field number 1

name: str

Alias for field number 2

model_id: str

Alias for field number 3

manufacturer_name: str

Alias for field number 4

sw_version: str

Alias for field number 5

unique_id: Optional[str]

Alias for field number 6

state: Union[hat.drivers.hue.common.LightState, hat.drivers.hue.common.SensorState]

Alias for field number 7

async hat.drivers.hue.create_user(addr, app_name='hat', dev_name='fv-az16')

Create new user

Register new user with bridge and return newly created username.

Parameters
  • addr (str) –

  • app_name (str) –

  • dev_name (str) –

Return type

str

class hat.drivers.hue.Client(addr, user)

Bases: object

High-level hue bridge client

Parameters
  • addr (str) –

  • user (str) –

property transport

Low-level transport

property closed

Closed future

async async_close()

Async close

Adds the closest light to the ZigBee network

async search()

Search for new devices

async rename(device_id, name)

Rename device

Parameters
  • device_id (hat.drivers.hue.common.DeviceId) –

  • name (str) –

async get_devices()

Get all devices

Return type

List[hat.drivers.hue.common.Device]

async get_device(device_id)
Parameters

device_id (hat.drivers.hue.common.DeviceId) –

Return type

hat.drivers.hue.common.Device

async set_state(device_id, state)
Parameters
  • device_id (hat.drivers.hue.common.DeviceId) –

  • state (Union[hat.drivers.hue.common.LightState, hat.drivers.hue.common.SensorState]) –

class hat.drivers.hue.ClientTransport(addr, user)

Bases: object

Low-level bridge client communication

Parameters
  • addr (str) –

  • user (str) –

property closed

Closed future

async async_close()

Async close

async get(device_id)

Get data

If device_id is None, global data is returned.

Parameters

device_id (Optional[hat.drivers.hue.common.DeviceId]) –

Return type

Union[None, bool, int, float, str, List[Data], Dict[str, Data]]

async search(device_type)

Search for new devices

Parameters

device_type (hat.drivers.hue.common.DeviceType) –

async rename(device_id, name)

Rename device

Parameters
  • device_id (hat.drivers.hue.common.DeviceId) –

  • name (str) –

async set_conf(device_id, data)

Set configuration

If device_id is None, global configuration is modified.

Light devices are not supported.

Parameters
  • device_id (Optional[hat.drivers.hue.common.DeviceId]) –

  • data (Union[None, bool, int, float, str, List[Data], Dict[str, Data]]) –

async set_state(device_id, data)

Set device state

Parameters
  • device_id (hat.drivers.hue.common.DeviceId) –

  • data (Union[None, bool, int, float, str, List[Data], Dict[str, Data]]) –