Skip to content

Commit

Permalink
Merge pull request #39 from junalmeida/fix-reset
Browse files Browse the repository at this point in the history
Accept decimal values on meter reset command; Fix build warnings
  • Loading branch information
junalmeida authored Nov 10, 2022
2 parents 0e3f850 + e1aa697 commit bbffde9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
changed=$(echo ${changed_addons[@]} | rev | cut -c 2- | rev)
if [[ -n ${changed} ]]; then
echo "Changed add-ons: $changed";
echo "::set-output name=changed::true";
echo "::set-output name=addons::[$changed]";
echo "changed=true" >> $GITHUB_OUTPUT;
echo "addons=[$changed]" >> $GITHUB_OUTPUT;
else
echo "No add-on had any monitored files changed (${{ env.MONITORED_FILES }})";
fi
Expand Down Expand Up @@ -78,14 +78,14 @@ jobs:
id: check
run: |
if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then
echo "::set-output name=build_arch::true";
echo "::set-output name=image::$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)";
echo "build_arch=true" >> $GITHUB_OUTPUT;
echo "image=$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)" >> $GITHUB_OUTPUT;
if [[ -z "${{ github.head_ref }}" ]] && [[ "${{ github.event_name }}" == "push" ]]; then
echo "BUILD_ARGS=" >> $GITHUB_ENV;
fi
else
echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build";
echo "::set-output name=build_arch::false";
echo "build_arch=false" >> $GITHUB_OUTPUT;
fi
- name: Login to GitHub Container Registry
if: env.BUILD_ARGS != '--test'
Expand Down Expand Up @@ -128,11 +128,11 @@ jobs:
- name: Get version
id: version
run: |
version="${{ steps.info.outputs.version }}"
version="${version%\"}"
version="${version#\"}"
echo $version
echo "::set-output name=result::$version"
version="${{ steps.info.outputs.version }}";
version="${version%\"}";
version="${version#\"}";
echo $version;
echo "result=$version" >> $GITHUB_OUTPUT;
- name: Create Release
id: create_release
Expand Down
5 changes: 5 additions & 0 deletions meterparser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### [1.0.1.5]

- Accept decimal values on meter reset command.
- Fix deprecated calls in build action.

### [1.0.1.4]

- Add `device_class` to water meter sensor.
Expand Down
2 changes: 1 addition & 1 deletion meterparser/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Meter Parser
version: 1.0.1.4
version: 1.0.1.5
slug: meter-parser
description: Read meter needles and numbers from a camera snapshot.
url: https://github.com/junalmeida/homeassistant-addons/tree/main/meterparser
Expand Down
15 changes: 10 additions & 5 deletions meterparser/src/app/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,17 @@ def send_image(self, image):
def set_callback(self, client, userdata, message):
try:
message = json.loads(message.payload.decode("utf-8"))
if message is not None and "value" in message and str(message["value"]).isnumeric():
self._current_reading = float(message["value"])
self._logger.info("Resetting %s (%s) to %d" % (
self.name, self.entity_id, self._current_reading))
data[self.entity_id] = self._current_reading
if message is not None and "value" in message:
self.reset(float(str(message["value"])))
elif message is not None:
self.reset(float(str(message)))
else:
self._logger.error("Invalid payload %s" % message)
except Exception as e:
self._logger.error("Invalid payload %s" % e)

def reset(self, value: float):
self._current_reading = value
self._logger.info("Resetting %s (%s) to %d" % (
self.name, self.entity_id, self._current_reading))
data[self.entity_id] = self._current_reading

0 comments on commit bbffde9

Please sign in to comment.