Files @ 8fc5da221688
Branch filter:

Location: light9/light9/newtypes.py

drewp@bigasterisk.com
checkpoint show data
from typing import NewType, Tuple, TypeVar, Union

from rdflib import Literal, URIRef

ClientType = NewType('ClientType', str)
ClientSessionType = NewType('ClientSessionType', str)
Curve = NewType('Curve', URIRef)
OutputUri = NewType('OutputUri', URIRef)  # e.g. dmxA
DeviceUri = NewType('DeviceUri', URIRef)  # e.g. :aura2
DeviceClass = NewType('DeviceClass', URIRef)  # e.g. :Aura
DmxIndex = NewType('DmxIndex', int)  # 1..512
DmxMessageIndex = NewType('DmxMessageIndex', int)  # 0..511
DeviceAttr = NewType('DeviceAttr', URIRef)  # e.g. :rx
EffectFunction = NewType('EffectFunction', URIRef)  # e.g. func:strobe
EffectUri = NewType('EffectUri', URIRef)  # unclear when to use this vs EffectClass
EffectAttr = NewType('EffectAttr', URIRef)  # e.g. :chaseSpeed
NoteUri = NewType('NoteUri', URIRef)
OutputAttr = NewType('OutputAttr', URIRef)  # e.g. :xFine
OutputValue = NewType('OutputValue', int)  # byte in dmx message
Song = NewType('Song', URIRef)
UnixTime = NewType('UnixTime', float)

VT = TypeVar('VT', float, int, str)  # remove
HexColor = NewType('HexColor', str)
VTUnion = Union[float, int, HexColor]  # rename to ValueType
DeviceSetting = Tuple[DeviceUri, DeviceAttr,
                      # currently, floats and hex color strings
                      VTUnion]

# Alternate output range for a device. Instead of outputting 0.0 to
# 1.0, you can map that range into, say, 0.2 to 0.7
OutputRange = NewType('OutputRange', Tuple[float, float])


def uriTail(u: URIRef) -> str:
    tail = u.rstrip('/').rsplit('/', 1)[1]
    if not tail:
        tail = str(u)
    return tail


def decimalLiteral(value):
    return Literal(value, datatype='http://www.w3.org/2001/XMLSchema#decimal')