Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename reading.compass to reading.heading for better "naming things" #18

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ calypso-anemometer changelog

in progress
===========
- Rename ``reading.compass`` to ``reading.heading`` for better "naming things"


2022-08-03 0.5.1
Expand Down
4 changes: 2 additions & 2 deletions calypso_anemometer/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
temperature=-100,
roll=-90,
pitch=-90,
compass=0,
heading=0,
)

MAXIMUM_VALUES = CalypsoReading(
Expand All @@ -29,7 +29,7 @@
temperature=+100,
roll=+90,
pitch=+90,
compass=360,
heading=360,
)


Expand Down
6 changes: 3 additions & 3 deletions calypso_anemometer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CalypsoReading:
temperature: int
roll: int
pitch: int
compass: int
heading: int

@classmethod
def from_buffer(cls, buffer: bytearray):
Expand Down Expand Up @@ -134,7 +134,7 @@ def from_buffer(cls, buffer: bytearray):
data = struct.unpack("<HHBBBBH", buffer)

# Decompose.
(wind_speed, wind_direction, battery_level, temperature, roll, pitch, compass) = data
(wind_speed, wind_direction, battery_level, temperature, roll, pitch, heading) = data

# Apply adjustments.
return cls(
Expand All @@ -144,7 +144,7 @@ def from_buffer(cls, buffer: bytearray):
temperature=temperature - 100,
roll=roll - 90,
pitch=pitch - 90,
compass=360 - compass,
heading=360 - heading,
)

def adjusted(self):
Expand Down
4 changes: 2 additions & 2 deletions calypso_anemometer/telemetry/signalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def set_reading(self, reading: CalypsoReading):
SignalKDeltaItem(path="environment.wind.speedApparent", value=reading.wind_speed),
SignalKDeltaItem(path="navigation.attitude.roll", value=reading.roll),
SignalKDeltaItem(path="navigation.attitude.pitch", value=reading.pitch),
SignalKDeltaItem(path="navigation.attitude.yaw", value=reading.compass),
SignalKDeltaItem(path="navigation.headingMagnetic", value=reading.compass),
SignalKDeltaItem(path="navigation.attitude.yaw", value=reading.heading),
SignalKDeltaItem(path="navigation.headingMagnetic", value=reading.heading),
# TODO: Improve `path` naming.
SignalKDeltaItem(path="electrical.batteries.99.name", value=self.source),
SignalKDeltaItem(path="electrical.batteries.99.location", value=self.location),
Expand Down
2 changes: 1 addition & 1 deletion examples/calypso_telemetry_nmea0183.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def calypso_nmea0183_telemetry_demo(host="255.255.255.255", port=10110):
temperature=33,
roll=30,
pitch=-60,
compass=235,
heading=235,
)

# Broadcast telemetry message, e.g. to OpenCPN.
Expand Down
2 changes: 1 addition & 1 deletion examples/calypso_telemetry_signalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def calypso_signalk_telemetry_demo(host="localhost", port=4123):
temperature=33,
roll=30,
pitch=-60,
compass=235,
heading=235,
)

# Submit telemetry message to SignalK.
Expand Down
2 changes: 1 addition & 1 deletion testing/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
temperature=33,
roll=30,
pitch=-60,
compass=235,
heading=235,
)

# Define example wire messages.
Expand Down
10 changes: 5 additions & 5 deletions testing/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_cli_fake_verbose(caplog):
Test `calypso-anemometer --verbose fake`
"""
fake_reading = CalypsoReading(
wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, compass=1
wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, heading=1
)
runner = CliRunner()
result = runner.invoke(cli, shlex.split("--verbose fake"), catch_exceptions=False)
Expand All @@ -62,7 +62,7 @@ def test_cli_fake_rate(caplog):
Test `calypso-anemometer --verbose fake --rate=hz_8`
"""
fake_reading = CalypsoReading(
wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, compass=1
wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, heading=1
)
runner = CliRunner()
result = runner.invoke(cli, shlex.split("--verbose fake --rate=hz_8"), catch_exceptions=False)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_cli_read_stdout_success(caplog):
response = json.loads(result.stdout)
assert response == {
"battery_level": 90,
"compass": 235,
"heading": 235,
"pitch": -60,
"roll": 30,
"temperature": 33,
Expand All @@ -134,7 +134,7 @@ def test_cli_read_stdout_success(caplog):
assert "Received buffer: b'9\\x02\\xce\\x00\\t\\x85x\\x1e}\\x00'" in caplog.messages
assert (
"Decoded reading: CalypsoReading(wind_speed=5.69, wind_direction=206, battery_level=90, "
"temperature=33, roll=30, pitch=-60, compass=235)" in caplog.messages
"temperature=33, roll=30, pitch=-60, heading=235)" in caplog.messages
)
assert "Disconnecting" in caplog.messages

Expand Down Expand Up @@ -213,7 +213,7 @@ def test_cli_read_telemetry_success(caplog):
response = json.loads(result.stdout)
assert response == {
"battery_level": 90,
"compass": 235,
"heading": 235,
"pitch": -60,
"roll": 30,
"temperature": 33,
Expand Down
2 changes: 1 addition & 1 deletion testing/test_core_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def test_reading_success(mocker: MockerFixture, caplog):
assert "Received buffer: b'9\\x02\\xce\\x00\\t\\x85x\\x1e}\\x00'" in caplog.messages
assert (
"Decoded reading: CalypsoReading(wind_speed=5.69, wind_direction=206, battery_level=90, "
"temperature=33, roll=30, pitch=-60, compass=235)" in caplog.messages
"temperature=33, roll=30, pitch=-60, heading=235)" in caplog.messages
)
assert "Disconnecting" in caplog.messages

Expand Down
2 changes: 1 addition & 1 deletion testing/test_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def test_subscribe_once():
await fake.subscribe_reading(callback=callback_mock, run_once=True)

callback_mock.assert_called_once_with(
CalypsoReading(wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, compass=1)
CalypsoReading(wind_speed=1, wind_direction=1, battery_level=1, temperature=-99, roll=-89, pitch=-89, heading=1)
)


Expand Down
6 changes: 3 additions & 3 deletions testing/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_decode_wiredata():
buffer = dummy_wire_message_good
data = CalypsoReading.from_buffer(buffer)
assert data == CalypsoReading(
wind_speed=5.69, wind_direction=206, battery_level=90, temperature=33, roll=30, pitch=-60, compass=235
wind_speed=5.69, wind_direction=206, battery_level=90, temperature=33, roll=30, pitch=-60, heading=235
)


Expand All @@ -34,7 +34,7 @@ def test_calypso_reading_vanilla():
"temperature": 33,
"roll": 30,
"pitch": -60,
"compass": 235,
"heading": 235,
}


Expand All @@ -53,7 +53,7 @@ def test_calypso_reading_adjusted():
"temperature": 33,
"roll": 30,
"pitch": -60,
"compass": 235,
"heading": 235,
}


Expand Down