Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Jul 28, 2024
2 parents 308b873 + 55c6fb1 commit dddb765
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.rubocop.yml
.vscode
coverage
docker-compose.yml
compose.yml
Dockerfile
Guardfile
Rakefile
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:3.3.4-alpine AS Builder
FROM ruby:3.3.4-alpine AS builder
RUN apk add --no-cache build-base

WORKDIR /mqtt-collector
Expand All @@ -15,21 +15,21 @@ LABEL maintainer="georg@ledermann.dev"
RUN apk add --no-cache tzdata

# Decrease memory usage
ENV MALLOC_ARENA_MAX 2
ENV MALLOC_ARENA_MAX=2

# Move build arguments to environment variables
ARG BUILDTIME
ENV BUILDTIME ${BUILDTIME}
ENV BUILDTIME=${BUILDTIME}

ARG VERSION
ENV VERSION ${VERSION}
ENV VERSION=${VERSION}

ARG REVISION
ENV REVISION ${REVISION}
ENV REVISION=${REVISION}

WORKDIR /mqtt-collector

COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
COPY . /mqtt-collector/

ENTRYPOINT bundle exec app.rb
ENTRYPOINT ["bundle", "exec", "app.rb"]
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GEM
dentaku (3.5.3)
concurrent-ruby
diff-lcs (1.5.1)
docile (1.4.0)
docile (1.4.1)
dotenv (3.1.2)
ffi (1.17.0)
formatador (1.1.0)
Expand Down Expand Up @@ -58,15 +58,15 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.0)
public_suffix (6.0.1)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
regexp_parser (2.9.2)
rexml (3.3.1)
rexml (3.3.2)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand Down Expand Up @@ -143,4 +143,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.5.15
2.5.16
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def value_from(message, mapping)
message = evaluate_from_json(message, mapping)
end

convert_type(message, mapping) if message
convert_type(message, mapping)
end

def convert_type(message, mapping)
Expand Down
29 changes: 22 additions & 7 deletions spec/lib/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,10 @@
].freeze

describe Mapper do
def default_config
@default_config ||= Config.new(VALID_ENV)
end
subject(:mapper) { described_class.new(config:) }

def mapper(config: nil)
Mapper.new(config: config || default_config)
end
let(:config) { Config.new(VALID_ENV, logger:) }
let(:logger) { MemoryLogger.new }

it 'has topics' do
expect(mapper.topics).to eq(EXPECTED_TOPICS)
Expand Down Expand Up @@ -414,10 +411,28 @@ def mapper(config: nil)
)
end

it 'maps NULL to 0' do
hash =
mapper.records_for('senec/0/WALLBOX/APPARENT_CHARGING_POWER/0', nil)

expect(hash).to eq(
[{ field: 'wallbox_power0', measurement: 'PV', value: 0 }],
)
end

it 'handles invalid JSON' do
hash = mapper.records_for('somewhere/ATTR', 'this is not JSON')

expect(hash).to eq([])
expect(logger.warn_messages).to include(/Failed to parse JSON/)
expect(hash).to eq(
[
{ field: 'leaving_temp', measurement: 'HEATPUMP', value: 0.0 },
{ field: 'inlet_temp', measurement: 'HEATPUMP', value: 0.0 },
{ field: 'water_flow', measurement: 'HEATPUMP', value: 0.0 },
{ field: 'temp_diff', measurement: 'HEATPUMP', value: 0.0 },
{ field: 'heat', measurement: 'HEATPUMP', value: 0.0 },
],
)
end

it 'handles invalid value types' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# # is tagged with `:focus`, all examples get run. RSpec also provides
# # aliases for `it`, `describe`, and `context` that include `:focus`
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# config.filter_run_when_matching :focus
config.filter_run_when_matching :focus
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
Expand Down

0 comments on commit dddb765

Please sign in to comment.