From 1dbfa8f3bee1dea510d5de1aa3ea1c2e1247c631 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Sat, 27 Apr 2019 10:24:07 -0500 Subject: [PATCH] Bump amcrest to 1.4.0 and use new storage_all method (#23446) Improve sdcard sensor so it only sends one command to camera per update as opposed to the four it used to send to reduce network traffic and make data consistent. Also better handle returned values of 'unknown'. --- homeassistant/components/amcrest/manifest.json | 2 +- homeassistant/components/amcrest/sensor.py | 18 +++++++++++++----- requirements_all.txt | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/amcrest/manifest.json b/homeassistant/components/amcrest/manifest.json index e05fdcf4bd4..a2eb8c24e21 100644 --- a/homeassistant/components/amcrest/manifest.json +++ b/homeassistant/components/amcrest/manifest.json @@ -3,7 +3,7 @@ "name": "Amcrest", "documentation": "https://www.home-assistant.io/components/amcrest", "requirements": [ - "amcrest==1.3.0" + "amcrest==1.4.0" ], "dependencies": [ "ffmpeg" diff --git a/homeassistant/components/amcrest/sensor.py b/homeassistant/components/amcrest/sensor.py index 4d2cd88c5ae..718d08358c4 100644 --- a/homeassistant/components/amcrest/sensor.py +++ b/homeassistant/components/amcrest/sensor.py @@ -84,8 +84,16 @@ class AmcrestSensor(Entity): self._state = self._api.ptz_presets_count elif self._sensor_type == 'sdcard': - sd_used = self._api.storage_used - sd_total = self._api.storage_total - self._attrs['Total'] = '{0} {1}'.format(*sd_total) - self._attrs['Used'] = '{0} {1}'.format(*sd_used) - self._state = self._api.storage_used_percent + storage = self._api.storage_all + try: + self._attrs['Total'] = '{:.2f} {}'.format(*storage['total']) + except ValueError: + self._attrs['Total'] = '{} {}'.format(*storage['total']) + try: + self._attrs['Used'] = '{:.2f} {}'.format(*storage['used']) + except ValueError: + self._attrs['Used'] = '{} {}'.format(*storage['used']) + try: + self._state = '{:.2f}'.format(storage['used_percent']) + except ValueError: + self._state = storage['used_percent'] diff --git a/requirements_all.txt b/requirements_all.txt index 1540a936b5b..b4a8d1bd75e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -161,7 +161,7 @@ alarmdecoder==1.13.2 alpha_vantage==2.1.0 # homeassistant.components.amcrest -amcrest==1.3.0 +amcrest==1.4.0 # homeassistant.components.androidtv androidtv==0.0.15