timex_datalink_caldav 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c7e200c3fbb1011bd0b0b67b98db758f8802b72d8686ceb991b4766cb285860
4
- data.tar.gz: e5b0052df0811f4af6f52c34727bd26bd93254903fdc218e9be00d51ae5ac169
3
+ metadata.gz: 8d31450cb602c3c36c121b4ffd2240664ed8f9e550388a246f1c5e169d12f7fa
4
+ data.tar.gz: 351b4213184ca2652205c80e99b7997538385bd0fab7e6ee3f4a6a57f1977247
5
5
  SHA512:
6
- metadata.gz: b07bd1855b0b9ffe5a36301c239df18f588bacfd7c1ba6f3e20988057cab7491343dc86072ad43bd5194e0c67e5d25ccb9d4f252214953dd8ed2a793819d9a72
7
- data.tar.gz: 529e2275b9207f501414c41131df0e505ae85e46ae8319a4ab0c04a35275b85be393c84b022e0e10890e3072ff4969a351aa55da453a3183b240bc9db19df94f
6
+ metadata.gz: '08bf1aa6454647ccc74a568cb0e54e5b9724394da3f0d8ff6a8bcb0205d63ddb35208b40d99cbdbdab0be8c6b6e5c0c6febdb9db3369c415bad5cfdba7be7cb5'
7
+ data.tar.gz: c2334ebf8d3d5515f4bce340808b61cacdc39ccdeaad6d2b7e7e356340fb97cf049c0316d1587d37b74dad9f4a593dcf91be66399bbfc3075018ef023a0e267d
data/Gemfile CHANGED
@@ -18,3 +18,5 @@ gem "icalendar", "~> 2.8"
18
18
  gem "icalendar-recurrence", "~> 1.1"
19
19
 
20
20
  gem "activesupport", "~> 7.0"
21
+
22
+ gem "tzinfo", "~> 2.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- timex_datalink_caldav (0.1.0)
4
+ timex_datalink_caldav (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -92,6 +92,7 @@ DEPENDENCIES
92
92
  rspec (~> 3.12)
93
93
  timex_datalink_caldav!
94
94
  timex_datalink_client (~> 0.11.0)
95
+ tzinfo (~> 2.0)
95
96
 
96
97
  BUNDLED WITH
97
98
  2.4.10
data/README.md CHANGED
@@ -45,14 +45,14 @@ After installing the gem, you can use it as a CLI tool:
45
45
  timex_datalink_caldav -u https://caldavendpoint.com -n your_username -p your_password -d your_device
46
46
  ```
47
47
 
48
- Please replace `your_username`, `your_password`, and `your_device` with your actual CalDAV server username, password, and device respectively. In this example, we're using Apple's iCloud CalDAV server. You'll need to replace this with the URI of your own CalDAV server if you're not using iCloud.
48
+ Please replace `caldavendpoint.com` `your_username`, `your_password`, and `your_device` with your actual CalDAV server, username, password, and serial device respectively.
49
49
 
50
- ## Note
50
+ The device is a serial device that flashes an led when it receives data. On Linux, this is usually `/dev/ttyUSB0`. On macOS, this is usually `/dev/cu.usbserial-0001`. On Windows, this is usually `COM1`.
51
51
 
52
- Ensure you have the necessary dependencies installed on your system and you have the correct permissions to access the specified device.
52
+ If you want to use this I highly recommend pairing it with the Raspberry Pi Pico and [this project](https://github.com/famiclone6502/DIY_Datalink_Adapter). It is the cheapest and easiest way to get a serial device that works with the Timex Datalink watch.
53
53
 
54
- The tool currently works with events that have attendees and converts event times to Eastern Standard Time (EST). Events are sorted by time before syncing to the watch.
54
+ ## Note
55
55
 
56
- ## Resources
56
+ Ensure you have the necessary dependencies installed on your system and you have the correct permissions to access the specified device.
57
57
 
58
- If you want to use this I highly recommend pairing it with the Raspberry Pi Pico and [this project](https://github.com/famiclone6502/DIY_Datalink_Adapter).
58
+ The tool currently filters down to events that have attendees and converts event times to Eastern Standard Time (EST). Events are sorted by time before syncing to the watch.
@@ -2,14 +2,27 @@ require 'calendav'
2
2
  require 'icalendar/recurrence'
3
3
  require 'timex_datalink_client'
4
4
  require 'active_support/time'
5
+ require 'tzinfo'
5
6
 
6
7
  module TimexDatalinkCaldav
7
8
  class Client
8
- def initialize(user, password, server_url, serial_device)
9
+ def initialize(user, password, server_url, serial_device, protocol_version)
9
10
  @user = user
10
11
  @password = password
11
12
  @server_url = server_url
12
13
  @serial_device = serial_device
14
+ @protocol_version = protocol_version.to_i
15
+ @protocol_class = case @protocol_version
16
+ when 1 then TimexDatalinkClient::Protocol1
17
+ when 3 then TimexDatalinkClient::Protocol3
18
+ when 4 then TimexDatalinkClient::Protocol4
19
+ else
20
+ raise ArgumentError, "Invalid protocol version: #{@protocol_version}"
21
+ end
22
+ end
23
+
24
+ def get_localzone
25
+ TZInfo::Timezone.get(TZInfo::Timezone.all_country_zones.detect {|z| z.period_for_local(Time.now).utc_total_offset == Time.now.utc_offset}.identifier)
13
26
  end
14
27
 
15
28
  def get_events
@@ -40,11 +53,12 @@ module TimexDatalinkCaldav
40
53
  if ical_event.attendee&.any? # Exclude events without attendees
41
54
  next_occurrence = ical_event.occurrences_between(Time.now, Time.now + 24*60*60).first
42
55
  if next_occurrence
43
- est_time = next_occurrence.start_time.in_time_zone('Eastern Time (US & Canada)')
56
+ puts get_localzone
57
+ est_time = next_occurrence.start_time.in_time_zone(get_localzone)
44
58
  key = "#{est_time}_#{ical_event.summary.to_s}"
45
59
  unless appointment_map[key] # Check if the event is already in the map
46
60
  puts "Adding appointment: #{ical_event.summary.to_s} at time #{est_time}"
47
- appointment = TimexDatalinkClient::Protocol1::Eeprom::Appointment.new(
61
+ appointment = @protocol_class::Eeprom::Appointment.new(
48
62
  time: est_time,
49
63
  message: ical_event.summary.to_s
50
64
  )
@@ -62,26 +76,62 @@ module TimexDatalinkCaldav
62
76
  end
63
77
 
64
78
  def write_to_watch(appointments)
65
- time1 = Time.now
66
-
67
- models = [
68
- TimexDatalinkClient::Protocol1::Sync.new,
69
- TimexDatalinkClient::Protocol1::Start.new,
70
- TimexDatalinkClient::Protocol1::Time.new(
79
+ # add 3 because it always seems to be about 3 seconds behind.
80
+ time1 = Time.now + 3
81
+ time2 = time1.dup.utc
82
+
83
+ if @protocol_version == 1
84
+ time_model = @protocol_class::Time.new(
71
85
  zone: 1,
72
86
  time: time1,
73
87
  is_24h: false
74
- ),
75
- TimexDatalinkClient::Protocol1::TimeName.new(
88
+ )
89
+ time_name_model = @protocol_class::TimeName.new(
76
90
  zone: 1,
77
91
  name: time1.zone
78
- ),
79
- TimexDatalinkClient::Protocol1::Eeprom.new(
92
+ )
93
+ utc_time_model = @protocol_class::Time.new(
94
+ zone: 2,
95
+ time: time2,
96
+ is_24h: true
97
+ )
98
+ utc_time_name_model = @protocol_class::TimeName.new(
99
+ zone: 2,
100
+ name: time2.zone
101
+ )
102
+ else
103
+ time_model = @protocol_class::Time.new(
104
+ zone: 1,
105
+ name: time1.zone,
106
+ time: time1,
107
+ is_24h: false,
108
+ date_format: "%_m-%d-%y"
109
+ )
110
+ utc_time_model = @protocol_class::Time.new(
111
+ zone: 2,
112
+ name: "UTC",
113
+ time: time2,
114
+ is_24h: true,
115
+ date_format: "%y-%m-%d"
116
+ )
117
+ time_name_model = nil # Not needed for protocol version 3 and 4
118
+ utc_time_name_model = nil # Not needed for protocol version 3 and 4
119
+
120
+ end
121
+
122
+ models = [
123
+ @protocol_class::Sync.new,
124
+ @protocol_class::Start.new,
125
+ time_model,
126
+ time_name_model,
127
+ utc_time_model,
128
+ utc_time_name_model,
129
+ @protocol_class::Eeprom.new(
80
130
  appointments: appointments,
81
131
  appointment_notification_minutes: 5
82
132
  ),
83
- TimexDatalinkClient::Protocol1::End.new
84
- ]
133
+ @protocol_class::End.new
134
+ ].compact # Remove any nil entries
85
135
 
86
136
  timex_datalink_client = TimexDatalinkClient.new(
87
137
  serial_device: @serial_device,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimexDatalinkCaldav
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require 'optparse'
3
-
4
3
  require_relative "timex_datalink_caldav/client"
5
4
 
6
5
  module TimexDatalinkCaldav
@@ -10,7 +9,7 @@ module TimexDatalinkCaldav
10
9
  end
11
10
 
12
11
  def execute
13
- client = TimexDatalinkCaldav::Client.new(@options.fetch(:user), @options.fetch(:password), @options.fetch(:uri), @options.fetch(:device))
12
+ client = TimexDatalinkCaldav::Client.new(@options.fetch(:user), @options.fetch(:password), @options.fetch(:uri), @options.fetch(:device), @options.fetch(:api,1))
14
13
  client.sync_to_watch
15
14
  end
16
15
 
@@ -36,6 +35,10 @@ module TimexDatalinkCaldav
36
35
  opts.on("-d", "--device DEVICE", "Serial device for Timex Datalink watch") do |v|
37
36
  options[:device] = v
38
37
  end
38
+
39
+ opts.on("-a", "--api PROTOCOL_VERSION", "Protocol Version") do |v|
40
+ options[:api] = v
41
+ end
39
42
  end.parse!(arguments)
40
43
  options
41
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timex_datalink_caldav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willy Hardy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Adds a CLI and a feature to pull your next day of calendar events into
14
14
  the Timex Datalink watch. Note: Hardcoded protocol1 and EST timezone. At the moment.'
@@ -19,7 +19,6 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".DS_Store"
23
22
  - CHANGELOG.md
24
23
  - Gemfile
25
24
  - Gemfile.lock
data/.DS_Store DELETED
Binary file