<commit_before># Hue controller
#
# Author:
#   sota1235

class HueController

  constructor: (ip, user) ->
    @ip   = ip
    @user = user
    @url  = "http://" + ip + "/api"

  request = (uri, method, data) ->
    dfd = $.Deferred()
    param =
      url    : @url + uri
      type   : method
      success: (msg) ->
        dfd.resolve $.parseJSON msg
        return dfd.promise()
      error  : (err) ->
        dfd.reject $.parseJSON err
        return dfd.promise()
    # add data to param if 'POST' or 'PUT'
    if method != 'GET'
      param['data'] = data
    $.ajax param

  getLights: () ->
    dfd = $.Deferred()
    uri = '/' + @user + 'lights'
    method = 'GET'
    request.call this, uri, method, null
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.reject()

  lightTrriger: (light, trigger) ->
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'on': if trigger then true else false
    request.call this, uri, method, data
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.promise()

  changeBri: (light, bri) ->
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'bri': bri
    request.call this, uri, method, data
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.promise()

  effectTrriget: (light, trigger) ->
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'effect': if trigger then 'colorloop' else 'none'
    request.call this, uri, method, data
      .then (result) -><commit_msg>TODOを追加, デルタでやる<commit_after># Hue controller
#
# Author:
#   sota1235

class HueController

  constructor: (ip, user) ->
    @ip   = ip
    @user = user
    @url  = "http://" + ip + "/api"

  request = (uri, method, data) ->
    dfd = $.Deferred()
    param =
      url    : @url + uri
      type   : method
      success: (msg) ->
        dfd.resolve $.parseJSON msg
        return dfd.promise()
      error  : (err) ->
        dfd.reject $.parseJSON err
        return dfd.promise()
    # add data to param if 'POST' or 'PUT'
    if method != 'GET'
      param['data'] = data
    $.ajax param

  getLights: () ->
    # TODO: jsonからライトの数だけ取り出してreturn
    dfd = $.Deferred()
    uri = '/' + @user + 'lights'
    method = 'GET'
    request.call this, uri, method, null
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.reject()

  lightTrriger: (light, trigger) ->
    # TODO: jsonから成功か否かを判別してbooleanでreturn
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'on': if trigger then true else false
    request.call this, uri, method, data
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.promise()

  changeBri: (light, bri) ->
    # TODO: jsonから成功か否かを取り出してbooleanでreturn
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'bri': bri
    request.call this, uri, method, data
      .then (result) ->
        dfd.resolve result
        return dfd.promise()
      .fail (err) ->
        dfd.reject err
        return dfd.promise()

  effectTrriget: (light, trigger) ->
    # TODO: jsonから成功か否かを取り出してbooleanでreturn
    uri = '/' + @user + '/lights/' + light.toString() + '/state'
    method = 'PUT'
    data =
      'effect': if trigger then 'colorloop' else 'none'
    request.call this, uri, method, data
      .then (result) ->
{'fraction_non_alphanumeric': 0.14875389408099687, 'fraction_numerical': 0.0020768431983385254, 'mean_word_length': 1.9101208459214503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '878565', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1315, 'n_words': 357}