Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/swimmy/command/attendance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class Attendance < Swimmy::Command::Base
client.say(channel: data.channel, text: "履歴を記録しました.")

# attendance event (for doorplate)
attendance_labels = {
"hi" => "在室",
"bye" => "帰宅"
}
doorplate_service = Swimmy::Service::Doorplate.new(mqtt_client)
doorplate_service.send_attendance_event(cmd, user_id, user_name)
doorplate_service.send_attendance_event(attendance_labels[cmd], user_name)
end

help do
Expand Down
2 changes: 1 addition & 1 deletion lib/swimmy/command/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Location < Swimmy::Command::Base
if match_locations.length == 1
begin
doorplate_service = Swimmy::Service::Doorplate.new(mqtt_client)
doorplate_service.send_attendance_event(match_locations.keys.first, user_id, user_name)
doorplate_service.send_attendance_event(match_locations.values.first, user_name)
rescue => e
client.say(channel: data.channel, text: "ドアプレートの状態を更新できませんでした.")
return
Expand Down
11 changes: 4 additions & 7 deletions lib/swimmy/service/doorplate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ def initialize(mqtt_client)
@mqtt = mqtt_client
end

def send_attendance_event(attendance, user_id, user_name)
def send_attendance_event(attendance, user_name)
require "json"

topic = "dt/swimmy/v1/ou/eng4/nomlab/swimmy/attend"
topic = "cmd/pinot/v1/ou/eng4/doormgr/state"
payload = JSON.dump({
attendance: attendance,
slack_user: {
id: user_id,
name: user_name,
},
member: user_name.tr('-','_'),
position: attendance,
})

@mqtt.publish(topic, payload)
Expand Down
Loading