<commit_before>_ = require('underscore')
Q = require('q')
[Capability] = require('../Capability')

module.exports = class ControlBrowserCapability extends Capability
  name: "Control Browser"

  naturalCommands:
    on:
      forms: [
        '(turn|switch) on( the)? <control>'
        '(turn|switch)( the)? <control> on']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control?.hasCommand('turnOn') then {control: control} else null
      execute: (cap, {control}) ->
        d = Q.defer()
        control.executeCommand('turnOn')
          .fail -> d.reject  "Sorry, that didn't work."
          .then -> d.resolve "Okay, turned on."
        d.promise
    off:
      forms: [
        '(turn|switch|shut) off( the)? <control>'
        '(turn|switch|shut)( the)? <control> off']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control?.hasCommand('turnOff') then {control: control} else null
      execute: (cap, {control}) ->
        d = Q.defer()
        control.executeCommand('turnOff')
          .fail -> d.reject  "Sorry, that didn't work."
          .then -> d.resolve "Okay, turned off."
        d.promise
    status:
      forms: [
        '(what is |describe|report )?(the )?(status|state) of( the)? <control>'
        '(what is |describe|report )?(the )?<control> (status|state)'
        '(is|are)( the)? <control> (on|off|open|closed|locked|unlocked)']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control? then {control: control} else null
      execute: (cap, {control}) ->
        Q.fcall => "#{control.get('name')} is #{control.describeCurrentState()}"

  start: ->
    # no-op server side
    @setValid true

  resolveControlName: (controlName) ->
    # XXX This should be much smarter
    controls = @_server.controls.select (control) ->
      _.contains(control.matchableNames(), controlName)
    if controls.length == 1 then controls[0] else undefined
<commit_msg>Natural: slightly expand status question form<commit_after>_ = require('underscore')
Q = require('q')
[Capability] = require('../Capability')

module.exports = class ControlBrowserCapability extends Capability
  name: "Control Browser"

  naturalCommands:
    on:
      forms: [
        '(turn|switch) on( the)? <control>'
        '(turn|switch)( the)? <control> on']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control?.hasCommand('turnOn') then {control: control} else null
      execute: (cap, {control}) ->
        d = Q.defer()
        control.executeCommand('turnOn')
          .fail -> d.reject  "Sorry, that didn't work."
          .then -> d.resolve "Okay, turned on."
        d.promise
    off:
      forms: [
        '(turn|switch|shut) off( the)? <control>'
        '(turn|switch|shut)( the)? <control> off']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control?.hasCommand('turnOff') then {control: control} else null
      execute: (cap, {control}) ->
        d = Q.defer()
        control.executeCommand('turnOff')
          .fail -> d.reject  "Sorry, that didn't work."
          .then -> d.resolve "Okay, turned off."
        d.promise
    status:
      forms: [
        '(what is |describe|report )?(the )?(status|state) of( the)? <control>'
        '(what is |describe|report )?(the )?<control> (status|state)'
        '(is|are)( the)? <control> (turned |switched |shut )?(on|off|open|closed|locked|unlocked)']
      resolve: (cap, {control}) ->
        control = cap.resolveControlName(control)
        if control? then {control: control} else null
      execute: (cap, {control}) ->
        Q.fcall => "#{control.get('name')} is #{control.describeCurrentState()}"

  start: ->
    # no-op server side
    @setValid true

  resolveControlName: (controlName) ->
    # XXX This should be much smarter
    controls = @_server.controls.select (control) ->
      _.contains(control.matchableNames(), controlName)
    if controls.length == 1 then controls[0] else undefined

{'fraction_non_alphanumeric': 0.15664403491755577, 'fraction_numerical': 0.0009699321047526673, 'mean_word_length': 2.7534121929026387, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818564', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1211, 'n_words': 328}