From 01c9d46d7d2957ff5fce109a5483d56349d3780d Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 16:19:30 +1300 Subject: [PATCH 01/10] Add override switch for juicenet --- homeassistant/components/juicenet/__init__.py | 6 ++- .../components/juicenet/manifest.json | 6 ++- homeassistant/components/juicenet/switch.py | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/juicenet/switch.py diff --git a/homeassistant/components/juicenet/__init__.py b/homeassistant/components/juicenet/__init__.py index a176236b22465..8622b2c6367fd 100644 --- a/homeassistant/components/juicenet/__init__.py +++ b/homeassistant/components/juicenet/__init__.py @@ -17,6 +17,8 @@ extra=vol.ALLOW_EXTRA, ) +JUICENET_COMPONENTS = ["sensor", "switch"] + def setup(hass, config): """Set up the Juicenet component.""" @@ -27,7 +29,9 @@ def setup(hass, config): access_token = config[DOMAIN].get(CONF_ACCESS_TOKEN) hass.data[DOMAIN]["api"] = pyjuicenet.Api(access_token) - discovery.load_platform(hass, "sensor", DOMAIN, {}, config) + for component in JUICENET_COMPONENTS: + discovery.load_platform(hass, component, DOMAIN, {}, config) + return True diff --git a/homeassistant/components/juicenet/manifest.json b/homeassistant/components/juicenet/manifest.json index 1ef84b74502a9..ab5b8e317bba3 100644 --- a/homeassistant/components/juicenet/manifest.json +++ b/homeassistant/components/juicenet/manifest.json @@ -3,8 +3,10 @@ "name": "Juicenet", "documentation": "https://www.home-assistant.io/integrations/juicenet", "requirements": [ - "python-juicenet==0.0.5" + "python-juicenet==0.1.4" ], "dependencies": [], - "codeowners": [] + "codeowners": [ + "@jesserockz" + ] } diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py new file mode 100644 index 0000000000000..4de82093cf820 --- /dev/null +++ b/homeassistant/components/juicenet/switch.py @@ -0,0 +1,53 @@ +"""Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" +import logging + +from homeassistant.components.switch import SwitchDevice + +from . import DOMAIN, JuicenetDevice + +_LOGGER = logging.getLogger(__name__) + + +def setup_platform(hass, config, add_entities, discovery_info=None): + """Set up the Juicenet sensor.""" + api = hass.data[DOMAIN]["api"] + + devs = [] + for device in api.get_devices(): + devs.append(JuicenetChargeNowSwitch(device, hass)) + + add_entities(devs) + + +class JuicenetChargeNowSwitch(JuicenetDevice, SwitchDevice): + """Implementation of a Juicenet switch.""" + + def __init__(self, device, hass): + """Initialise the switch.""" + super().__init__(device, "charge_now", hass) + + @property + def name(self): + """Return the name of the device.""" + return "{} {}".format(self.device.name(), "Charge Now") + + @property + def state(self): + """Return the state.""" + if self.device.getOverrideTime() != 0: + return "on" + else: + return "off" + + @property + def is_on(self): + """Return true if switch is on.""" + return self.device.getOverrideTime() != 0 + + def turn_on(self, **kwargs): + """Charge now.""" + self.device.setOverride(True) + + def turn_off(self, **kwargs): + """Don't charge now.""" + self.device.setOverride(False) From cc557bf671e39554368a3da8ed1998d1ea5c0250 Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 16:46:38 +1300 Subject: [PATCH 02/10] Update generated files --- CODEOWNERS | 1 + requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 30946fb14f235..0bb535611a631 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -155,6 +155,7 @@ homeassistant/components/iqvia/* @bachya homeassistant/components/irish_rail_transport/* @ttroy50 homeassistant/components/izone/* @Swamp-Ig homeassistant/components/jewish_calendar/* @tsvi +homeassistant/components/juicenet/* @jesserockz homeassistant/components/kaiterra/* @Michsior14 homeassistant/components/keba/* @dannerph homeassistant/components/keenetic_ndms2/* @foxel diff --git a/requirements_all.txt b/requirements_all.txt index 3c649e9175657..ace13c158b339 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1525,7 +1525,7 @@ python-izone==1.1.1 python-join-api==0.0.4 # homeassistant.components.juicenet -python-juicenet==0.0.5 +python-juicenet==0.1.4 # homeassistant.components.lirc # python-lirc==1.2.3 From 200ebedf6458a3057f48b5473ee086fcbff4b566 Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 16:54:53 +1300 Subject: [PATCH 03/10] Update indentation --- homeassistant/components/juicenet/switch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 4de82093cf820..2a26c2ad6debf 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -41,13 +41,13 @@ def state(self): @property def is_on(self): - """Return true if switch is on.""" - return self.device.getOverrideTime() != 0 + """Return true if switch is on.""" + return self.device.getOverrideTime() != 0 def turn_on(self, **kwargs): - """Charge now.""" - self.device.setOverride(True) + """Charge now.""" + self.device.setOverride(True) def turn_off(self, **kwargs): - """Don't charge now.""" - self.device.setOverride(False) + """Don't charge now.""" + self.device.setOverride(False) From 764d1603fe693b532bf6616947296246367906db Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 17:15:21 +1300 Subject: [PATCH 04/10] Fix indentation --- homeassistant/components/juicenet/switch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 2a26c2ad6debf..364c1f8db4fde 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -35,9 +35,9 @@ def name(self): def state(self): """Return the state.""" if self.device.getOverrideTime() != 0: - return "on" + return "on" else: - return "off" + return "off" @property def is_on(self): From a2cd0232ce17d4cbe5fc882ce9dceeeeee431ee1 Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 19:38:50 +1300 Subject: [PATCH 05/10] Remove unnecessary else statement --- homeassistant/components/juicenet/switch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 364c1f8db4fde..f985fcf71f046 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -36,8 +36,7 @@ def state(self): """Return the state.""" if self.device.getOverrideTime() != 0: return "on" - else: - return "off" + return "off" @property def is_on(self): From 1f7549f6caec75533366f4b55a45b2eab15dcd6f Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 21 Oct 2019 22:17:45 +1300 Subject: [PATCH 06/10] Update homeassistant/components/juicenet/switch.py Co-Authored-By: Fabian Affolter --- homeassistant/components/juicenet/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index f985fcf71f046..c77b661822267 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -9,7 +9,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the Juicenet sensor.""" + """Set up the Juicenet switch.""" api = hass.data[DOMAIN]["api"] devs = [] From fd11925949e1c4b2e80ed149ed52e6fe5035ee6e Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 21 Oct 2019 22:18:03 +1300 Subject: [PATCH 07/10] Update homeassistant/components/juicenet/switch.py Co-Authored-By: Fabian Affolter --- homeassistant/components/juicenet/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index c77b661822267..67ba54350cc25 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -1,4 +1,4 @@ -"""Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" +"""Support for monitoring juicenet/juicepoint/juicebox based EVSE switches.""" import logging from homeassistant.components.switch import SwitchDevice From 387cb6d97b4883f40bee26d44e2bd034d2615f8d Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 22:18:59 +1300 Subject: [PATCH 08/10] Remove state property --- homeassistant/components/juicenet/switch.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 67ba54350cc25..0dc6abe0cdd19 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -31,13 +31,6 @@ def name(self): """Return the name of the device.""" return "{} {}".format(self.device.name(), "Charge Now") - @property - def state(self): - """Return the state.""" - if self.device.getOverrideTime() != 0: - return "on" - return "off" - @property def is_on(self): """Return true if switch is on.""" From 7425c217ac6c2f08620b44ce5ed504e6e0714734 Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Mon, 21 Oct 2019 22:19:56 +1300 Subject: [PATCH 09/10] Change string formatting --- homeassistant/components/juicenet/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/juicenet/switch.py b/homeassistant/components/juicenet/switch.py index 0dc6abe0cdd19..30bb5b22814a1 100644 --- a/homeassistant/components/juicenet/switch.py +++ b/homeassistant/components/juicenet/switch.py @@ -29,7 +29,7 @@ def __init__(self, device, hass): @property def name(self): """Return the name of the device.""" - return "{} {}".format(self.device.name(), "Charge Now") + return f"{self.device.name()} Charge Now" @property def is_on(self): From 1b134788e46115ffb13257986248ca6ea18ba61f Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Tue, 29 Oct 2019 09:51:24 +1300 Subject: [PATCH 10/10] Bump juicenet package version again --- homeassistant/components/juicenet/manifest.json | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/juicenet/manifest.json b/homeassistant/components/juicenet/manifest.json index ab5b8e317bba3..076567573c724 100644 --- a/homeassistant/components/juicenet/manifest.json +++ b/homeassistant/components/juicenet/manifest.json @@ -3,7 +3,7 @@ "name": "Juicenet", "documentation": "https://www.home-assistant.io/integrations/juicenet", "requirements": [ - "python-juicenet==0.1.4" + "python-juicenet==0.1.5" ], "dependencies": [], "codeowners": [ diff --git a/requirements_all.txt b/requirements_all.txt index ace13c158b339..6b2ce55126260 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1525,7 +1525,7 @@ python-izone==1.1.1 python-join-api==0.0.4 # homeassistant.components.juicenet -python-juicenet==0.1.4 +python-juicenet==0.1.5 # homeassistant.components.lirc # python-lirc==1.2.3