コード例 #1
0
class SceneStateChange(Resource):
    """
    ``SceneStateChange`` work differently to :class:`LightState` and
    :class:`GroupState`. ``SceneStateChange`` specifies a change in
    state for a specific scene & light combination.

    For example, to change light ID 1 in scene `e2eab6bf6-on-0` to `on`::

        change = SceneStateChange(
            scene=Scene.objects.get(id='e2eab6bf6-on-0'),
            light=Light.objects.get(id=1),
        )
        change.on = True
        change.save()

    """

    #: The scene to which this change applies
    scene = fields.Embedded(model=Scene, read_only=True)
    #: The light to which this scene applies
    light = fields.Embedded(model=Light, read_only=True)
    #: On/Off state of the light. On=true, Off=false
    on = fields.Boolean()
    #: Brightness of the light. This is a scale from the minimum brightness
    #: the light is capable of, 1, to the maximum capable brightness, 254.
    brightness = fields.Integer(v.UnsignedInteger(bits=8), name='bri')
    #: The hue value is a wrapping value between 0 and 65535.
    #: Both 0 and 65535 are red, 25500 is green and 46920 is blue.
    hue = fields.Integer(v.UnsignedInteger(bits=16))
    #: Saturation of the light. 255 is the most saturated (colored) and 0
    #: is the least saturated (white).
    saturation = fields.Integer(v.UnsignedInteger(bits=8), name='sat')
    #: The x and y coordinates of a color in CIE color space.
    xy = fields.List(v.CieColorSpaceCoordinates())
    #: The Mired Color temperature of the light. 2012 connected lights are
    #: capable of 153 (6500K) to 500 (2000K).
    color_temperature = fields.Integer(v.UnsignedInteger(bits=16), name='ct')
    #: The duration of the transition from the light's current state to the
    #: new state. This is given as a multiple of 100ms.
    transition_time = fields.Integer(v.UnsignedInteger(bits=16),
                                     name='transitiontime')

    class Meta:
        endpoint = '/scenes/{scene_id}/lights/{light_id}/state'

    def get_endpoint_values(self):
        return {
            'scene_id': self.scene.id,
            'light_id': self.light.id,
        }
コード例 #2
0
ファイル: __init__.py プロジェクト: adamcharnock/repose
class Post(Resource):
    id = fields.Integer()
    content = fields.String()

    class Meta:
        endpoint = '/user/{user_id}/post/{post_id}'
        endpoint_list = '/user/{user_id}/post'
コード例 #3
0
class User(Resource):
    id = fields.Integer()
    login = fields.String()
    avatar_url = fields.String()
    location = fields.String()
    site_admin = fields.Boolean()

    class Meta:
        # Endpoint for getting a single specific user
        endpoint = '/users/{login}'
        # Endpoint for listing all users
        endpoint_list = '/users'
コード例 #4
0
class Repository(Resource):
    id = fields.Integer()
    name = fields.String()
    full_name = fields.String()
    description = fields.String()
    owner = fields.Embedded(User)

    class Meta:
        # Endpoint for getting a single specific repository
        endpoint = '/repos/{full_name}'
        # Endpoint for listing all repositories
        endpoint_list = '/repositories'
コード例 #5
0
ファイル: __init__.py プロジェクト: adamcharnock/repose
class User(Resource):
    id = fields.Integer()
    name = fields.String()
    posts = fields.ManagedCollection(Post)
    profile = fields.Embedded(Profile)

    objects = Manager()
    with_posts = Manager(filter=lambda u: u.posts.count() > 0)

    class Meta:
        endpoint = '/user/{user_id}'
        endpoint_list = '/user'
コード例 #6
0
class Scene(MonitorMixin, Resource):
    """
    Note that scene state is not available on this resource
    as scene state is write-only. See :class:`SceneStateChange` for details.
    """

    #: The ID given to the scene by the bridge (alphanumeric, Eg: `s123457`)
    id = fields.Integer(v.UnsignedInteger(), from_endpoint='id')
    #: An editable name given to the scene
    name = fields.String(v.Required())
    #: The Light resources effected by this scene
    lights = fields.ManagedIdListCollection(model=Light)
    #: Is this scene active?
    active = fields.Boolean()

    objects = SceneManager()

    class Meta:
        endpoint = '/scenes/{id}'
        endpoint_list = '/scenes'
コード例 #7
0
ファイル: __init__.py プロジェクト: adamcharnock/repose
class Profile(Resource):
    email = fields.String()
    age = fields.Integer()