tinderfridge 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5370c2b6210bbb986208ce2afc7f6ce9573592b7707bf14a8bc371ffb47050c
4
- data.tar.gz: 79338d5081d87b1aff9402eaf656be89ed5a50c52f59f597c68a84e9462ccdd4
3
+ metadata.gz: d3c51a0740fb7714bbb9012543195df2539e310653510dfd6f6b4972aaf4b7dd
4
+ data.tar.gz: d02f24ea04041305ac5cc7b40c73e651451bca9caff08be1476bc592ac9fe56b
5
5
  SHA512:
6
- metadata.gz: c0077e242170d67d5c8ffdc63efd702183865d2e475c4be0c0f93bc4bf33aff1c313838a96ade44255245c320057e5369133d860fd5755b585f0fa92f1ae823c
7
- data.tar.gz: 3a98205cf201dd8df8ca95378ad1bb82fa41af517f2f8b87a910f4f43b7753344ea0538d90aab6015fd3b8d16d2627b3ef24167380457601cf20f7aae19addfe
6
+ metadata.gz: 8d8e2423d20924eb5bcb96083268c337d3dbbb571f395d1d6861ce39de4f2391784de84674b59875fea61a0dc9aca7085aa41c7a7274362394582a6453d5cf5a
7
+ data.tar.gz: 838806023856f1f566b4f49ce73b04ff6d1bae47b395e7b7d089ee288e1ed0ad85396fda76d7401866dea848b0288fd6be4a6cc1a8e306c0a11a192f09582445
@@ -97,10 +97,17 @@ module Tinkerforge
97
97
 
98
98
  # Returns the device's properties.
99
99
  def properties
100
- @properties ||= {
101
- 'device_identifier' => device_identifier,
102
- 'device_display_name' => device_display_name,
103
- }.merge load_properties
100
+
101
+ # BrickDaemon inherits from Device, but has no #get_identity.
102
+ return {} unless respond_to? 'get_identity'
103
+
104
+ identity = get_identity
105
+
106
+ @properties ||= [
107
+ [ 'device_identifier' , device_identifier ],
108
+ [ 'device_display_name', device_display_name ],
109
+ [ 'hardware_version' , identity[3].join('.') ],
110
+ ].compact.to_h.merge load_properties
104
111
  end
105
112
 
106
113
  alias props properties
@@ -2,6 +2,8 @@ module Tinkerforge
2
2
 
3
3
  class DeviceCollection < Hash
4
4
 
5
+ alias devices values
6
+
5
7
  # Returns the temperatures as measured inside the microcontrollers of devices in the collection.
6
8
  #
7
9
  # Nil for devices that do not support the get_chip_temperature method.
@@ -125,9 +127,11 @@ module Tinkerforge
125
127
  smap('ipcon').values.compact.uniq
126
128
  end
127
129
 
128
- # Disconnects IP Connections used by devices in the collection.
130
+ # Disconnects IP Connections used by devices in the collection, and removes all devices from the collection.
129
131
  def disconnect
130
- ipcons.map { |i| [i, (i.get_connection_state == 0 ? nil : i.disconnect) ] }.to_h
132
+ result = ipcons.map { |i| [i, (i.get_connection_state == 0 ? nil : i.disconnect) ] }.to_h
133
+ clear
134
+ result
131
135
  end
132
136
 
133
137
  # Returns an array of devices in the collection matching the selector.
@@ -6,6 +6,55 @@ module Tinkerforge
6
6
  CHIP_TEMPERATURE_UNIT = 0.1
7
7
  # REVIEW: This should ideally be part of base Tinkerforge.
8
8
 
9
+ # Returns the device's state.
10
+ def state
11
+ super.merge [
12
+ safe_send_state('connection_type' , 'get_connection_type' ), # FW 2.4.0
13
+ safe_send_state('status_led_enabled', 'is_status_led_enabled'), # FW 2.3.2
14
+ safe_send_state('chibi_present' , 'is_chibi_present' ),
15
+ safe_send_state('rs485_present' , 'is_rs485_present' ),
16
+ safe_send_state('ethernet_present' , 'is_ethernet_present' ), # FW 2.1.0
17
+ safe_send_state('wifi_present' , 'is_wifi_present' ),
18
+ safe_send_state('wifi2_present' , 'is_wifi2_present' ), # FW 2.4.0
19
+ ].compact.to_h
20
+ end
21
+
22
+ # Returns the state of the WIFI Extension 2.0.
23
+ def wifi2_state
24
+ if is_wifi2_present
25
+ [
26
+ safe_send_state('mesh_configuration' , 'get_wifi2_mesh_configuration' ), # FW 2.4.2 / 2.1.0
27
+ safe_send_state('mesh_router_ssid' , 'get_wifi2_mesh_router_ssid' ), # FW 2.4.2 / 2.1.0
28
+ safe_send_state('mesh_common_status' , 'get_wifi2_mesh_common_status' ), # FW 2.4.2 / 2.1.0
29
+ safe_send_state('mesh_client_status' , 'get_wifi2_mesh_client_status' ), # FW 2.4.2 / 2.1.0
30
+ safe_send_state('mesh_ap_status' , 'get_wifi2_mesh_ap_status' ), # FW 2.4.2 / 2.1.0
31
+ safe_send_state('configuration' , 'get_wifi2_configuration' ), # FW 2.4.0
32
+ safe_send_state('status' , 'get_wifi2_status' ), # FW 2.4.0
33
+ safe_send_state('client_configuration', 'get_wifi2_client_configuration'), # FW 2.4.0
34
+ safe_send_state('client_hostname' , 'get_wifi2_client_hostname' ), # FW 2.4.0
35
+ safe_send_state('ap_configuration' , 'get_wifi2_ap_configuration' ), # FW 2.4.0
36
+
37
+ if r = safe_send_state('firmware_version', 'get_wifi2_firmware_version' ) # FW 2.4.0
38
+ [ r[0], r[1].join('.') ]
39
+ end
40
+ ].compact.to_h
41
+ end
42
+ rescue
43
+ nil
44
+ end
45
+
46
+ private
47
+
48
+ # Safely call a method for inclusion in state hash.
49
+ # When method blows up, state can ignore it.
50
+ # REVIEW: possible candidate for Device class
51
+ def safe_send_state(key, methot)
52
+ [key, send(methot)]
53
+ rescue => e
54
+ logger_warn "Device '#{uid_string}': '#{methot}' failed. #{e}"
55
+ nil
56
+ end
57
+
9
58
  end
10
59
 
11
60
  end
@@ -16,6 +16,14 @@ module Tinkerforge
16
16
 
17
17
  private
18
18
 
19
+ def _print_4
20
+ if (co2 = get_co2_concentration) > 9999
21
+ ' ol '
22
+ else
23
+ '%4d' % co2
24
+ end
25
+ end
26
+
19
27
  def _view_21x8
20
28
  "CO2V2 #{uid_string.rjust 8}\n\n\n" +
21
29
  ('%d PPM' % get_co2_concentration).center(21)
@@ -0,0 +1,38 @@
1
+ module Tinkerforge
2
+
3
+ class BrickletParticulateMatter
4
+
5
+ # Enables the fan and the laser diode.
6
+ def enable
7
+ set_enable true
8
+ end
9
+
10
+ # Disables the fan and the laser diode.
11
+ def disable
12
+ set_enable false
13
+ end
14
+
15
+ # Returns the device's state.
16
+ def state
17
+ super.merge(
18
+ 'enabled' => get_enable,
19
+ 'pm_concentration' => get_pm_concentration,
20
+ 'pm_count' => get_pm_count,
21
+ 'sensor_info' => get_sensor_info,
22
+ )
23
+ end
24
+
25
+ private
26
+
27
+ def _view_21x8
28
+ "PM #{uid_string.rjust 8}\n\n" +
29
+ if get_enable
30
+ " PM1 %4d\n PM2.5 %4d\n PM10 %4d" % get_pm_concentration
31
+ else
32
+ "\n disabled"
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -35,30 +35,39 @@ module Tinkerforge
35
35
  self.segments = segments.gsub(/[ _]/, '').ljust(35, '0').chars.map { |s| s == '1' }
36
36
  end
37
37
 
38
+ # Turns all 35 segments on.
39
+ def all_on
40
+ self.segments = [true]*35
41
+ end
42
+
38
43
  # Returns the device's state.
39
44
  def state
40
45
  super.merge( 'brightness' => get_brightness )
41
46
  end
42
47
 
43
48
  # Displays a string.
44
- def print(text='')
45
- out = ''
46
- colon = false
47
-
48
- text.to_s.chars.each do |c|
49
- if glyphs.key? c
50
- out << glyphs[c] << '0'
51
- elsif c == '.' and out[-1] == '0'
52
- out[-1] = '1'
53
- elsif c == ':' and out.size == 16
54
- colon = true
55
- else
56
- raise "Can not display '#{text}'"
49
+ def print(text_or_object='')
50
+ if text_or_object.respond_to?( :_print_4, true)
51
+ print ( text_or_object.send(:_print_4) rescue '' )
52
+ else
53
+ out = ''
54
+ colon = false
55
+
56
+ text_or_object.to_s.chars.each do |c|
57
+ if glyphs.key? c
58
+ out << glyphs[c] << '0'
59
+ elsif c == '.' and out[-1] == '0'
60
+ out[-1] = '1'
61
+ elsif c == ':' and out.size == 16
62
+ colon = true
63
+ else
64
+ raise "Can not display '#{text}'"
65
+ end
57
66
  end
58
- end
59
67
 
60
- self.segments_string = out[0,32].ljust(32,'0') + ( colon ? '110' : '000' )
61
- nil
68
+ self.segments_string = out[0,32].ljust(32,'0') + ( colon ? '110' : '000' )
69
+ nil
70
+ end
62
71
  end
63
72
 
64
73
  # Returns the definition of glyphs for Unicode chracters.
@@ -78,6 +87,7 @@ module Tinkerforge
78
87
 
79
88
  'A' => '1110111',
80
89
  'b' => '0011111',
90
+ 'B' => '1111111',
81
91
  'c' => '0001101',
82
92
  'C' => '1001110',
83
93
  'd' => '0111101',
@@ -91,6 +101,7 @@ module Tinkerforge
91
101
  'J' => '0111000',
92
102
  'L' => '0001110',
93
103
  'l' => '0001100',
104
+ 'N' => '1110110',
94
105
  'n' => '0010101',
95
106
  'O' => '1111110',
96
107
  'o' => '0011101',
@@ -103,7 +114,8 @@ module Tinkerforge
103
114
  'u' => '0011100',
104
115
  'V' => '0111110',
105
116
  'v' => '0011100',
106
- 'y' => '0110011',
117
+ 'Y' => '0111011',
118
+ 'y' => '0111011',
107
119
 
108
120
  'ö' => '1011101',
109
121
  'ü' => '1011100',
@@ -16,6 +16,24 @@ module Tinkerforge
16
16
  # Returns the network socket used by the IP Connection.
17
17
  attr_reader :socket
18
18
 
19
+ alias original_connect connect
20
+
21
+ # Creates a TCP/IP connection to the given host and port. Logs events if event logging is enabled.
22
+ def connect(host, port)
23
+ logger_debug "Connecting to #{host}:#{port}"
24
+ original_connect(host, port)
25
+ logger_debug "Connected to #{host}:#{port}"
26
+ end
27
+
28
+ alias original_disconnect disconnect
29
+
30
+ # Disconnects the TCP/IP connection. Logs events if event logging is enabled.
31
+ def disconnect
32
+ logger_debug "Disconnecting from #{host}:#{port}"
33
+ original_disconnect
34
+ logger_debug "Disconnected from #{host}:#{port}"
35
+ end
36
+
19
37
  # Returns a programmer-friendly representation of the object.
20
38
  def inspect
21
39
  "#{self.class} (%s:%s)" % (host ? [host, port] : ['-', '-'] )
@@ -3,7 +3,7 @@ require 'tinkerforge/version'
3
3
  module Tinkerforge
4
4
 
5
5
  # Tinderfridge version.
6
- TINDERFRIDGE_VERSION = '0.14.0'
6
+ TINDERFRIDGE_VERSION = '0.15.0'
7
7
 
8
8
  # About Tinkerforge & Tinderfridge.
9
9
  def self.about
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinderfridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lllist.eu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2024-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tinkerforge
@@ -120,6 +120,7 @@ files:
120
120
  - lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.json
121
121
  - lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb
122
122
  - lib/tinderfridge/devices/bricklet_particulate_matter/bricklet_particulate_matter.json
123
+ - lib/tinderfridge/devices/bricklet_particulate_matter/bricklet_particulate_matter.rb
123
124
  - lib/tinderfridge/devices/bricklet_performance_dc/bricklet_performance_dc.json
124
125
  - lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.json
125
126
  - lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.rb