Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added toggle function for dimmers #812

Merged
merged 1 commit into from
Mar 12, 2016
Merged

Added toggle function for dimmers #812

merged 1 commit into from
Mar 12, 2016

Conversation

sweebee
Copy link
Contributor

@sweebee sweebee commented Feb 15, 2016

No description provided.

@sweetpi
Copy link
Contributor

sweetpi commented Feb 24, 2016

Sorry for the late response.

@sweebee Could you use getState instead (see the toggle function of thw switch device)?

@sweebee
Copy link
Contributor Author

sweebee commented Feb 24, 2016

I can't get it working.

Error on evaluation of rule condition of rule test: Function "changeStateTo" is not implemented!

Dimmer:

class DimmerActuator extends SwitchActuator
    _dimlevel: null

    actions:
      changeDimlevelTo:
        description: "Sets the level of the dimmer"
        params:
          dimlevel:
            type: t.number
      changeStateTo:
        description: "Changes the switch to on or off"
        params:
          state:
            type: t.boolean
      turnOn:
        description: "Turns the dim level to 100%"
      turnOff:
        description: "Turns the dim level to 0%"
      toggle:
        description: "Toggle the state of the dimmer"
      getState:
        description: "Returns the current state of the dimmer"
        returns:
          state:
            type: t.boolean

    attributes:
      dimlevel:
        description: "The current dim level"
        type: t.number
        unit: "%"
      state:
        description: "The current state of the switch"
        type: t.boolean
        labels: ['on', 'off']


    template: "dimmer"

    # Returns a promise
    turnOn: -> @changeDimlevelTo 100

    # Retuns a promise
    turnOff: -> @changeDimlevelTo 0

    toggle: ->
      @getState().then( (state) => @changeStateTo(!state) )

    # Retuns a promise that is fulfilled when done.
    changeStateTo: (state) ->
      throw new Error "Function \"changeStateTo\" is not implemented!"

    # Retuns a promise that is fulfilled when done.
    changeDimlevelTo: (state) ->
      throw new Error "Function \"changeDimlevelTo\" is not implemented!"

    _setDimlevel: (level) =>
      level = parseFloat(level)
      assert(not isNaN(level))
      cassert level >= 0
      cassert level <= 100
      if @_dimlevel is level then return
      @_dimlevel = level
      @emit "dimlevel", level
      @_setState(level > 0)

    # Returns a promise that will be fulfilled with the dim level
    getDimlevel: -> Promise.resolve(@_dimlevel)

    # Returns a promise that will be fulfilled with the state
    getState: -> Promise.resolve(@_state)

@ds2216
Copy link
Contributor

ds2216 commented Feb 28, 2016

what about changing

changeStateTo: (state) ->
  throw new Error "Function \"changeStateTo\" is not implemented!"

to

changeStateTo: (state) ->
  @_setState(state)
  return Promise.resolve()

?

@Icesory
Copy link
Contributor

Icesory commented Feb 28, 2016

This is the dimmer prototype so it isn't good to implement per device functions in the parent.

_setState() dose not run any code for the real device. So you can change the device in pimatic but no Logik to send this information to its target runs. This will not work.

Every dimmer device must implement the changeStateTo function. @sweebee for which device did you try to implement it? You must create a pull request for this dimmer and implement the changeStateTo function.

sweetpi added a commit that referenced this pull request Mar 12, 2016
Added toggle function for dimmers
@sweetpi sweetpi merged commit eef22eb into pimatic:master Mar 12, 2016
@sweetpi
Copy link
Contributor

sweetpi commented Mar 12, 2016

I merged it but removed the toggle function because it is already in the SwitchActuator. I also added a default changeStateTo dunction to the dimmer device.

The addition will be released with the next version. Sorry for the long delay on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants