Example #1
0
def cleanup(*args):
    if iGoe > 20:
        # Besser fuer die Sicherung:
        print("Stelle Goe auf 15 Ampere ... Warte 10s")
        goeCharger.setMaxCurrent(15)
        time.sleep(10)

    os._exit(0)

    if iGoe > 14:
        # Besser fuer die Sicherung:
        print("Stelle Goe auf 10 Ampere ... Warte 10s")
        goeCharger.setMaxCurrent(10)
        time.sleep(10)

    os._exit(0)

    if iGoe > 10:
        print("Stelle Goe auf 6 Ampere ... Warte 10s")
        goeCharger.setMaxCurrent(6)
        time.sleep(10)

    try:
        GoeCharger(GOE_IP).setAllowCharging(1)
        print("Eingestellt auf Charging 6 Ampere")
    except Exception:
        print("Goe ist nicht erreichbar (1)")

    os._exit(0)
Example #2
0
async def async_setup_entry(
    hass: core.HomeAssistant,
    config_entry: config_entries.ConfigEntry,
    async_add_entities,
):
    _LOGGER.debug("setup switch...")
    _LOGGER.debug(repr(config_entry.as_dict()))
    config = config_entry.as_dict()["data"]

    chargerName = config[CONF_NAME]
    host = config[CONF_HOST]
    chargerApi = GoeCharger(host)

    entities = []

    attribute = "allow_charging"
    entities.append(
        GoeChargerSwitch(
            hass.data[DOMAIN]["coordinator"],
            hass,
            chargerApi,
            f"switch.goecharger_{chargerName}_{attribute}",
            chargerName,
            "Charging allowed",
            attribute,
        )
    )

    async_add_entities(entities)
Example #3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up go-eCharger Sensor platform."""

    if discovery_info is None:
        return

    serial = hass.data[DOMAIN]['serial_number']

    goeCharger = GoeCharger(discovery_info[CONF_HOST])

    entities = []

    sensorUnits = {
        'charger_temp': {'unit': TEMP_CELSIUS, 'name': 'Charger Temp'},
        'p_l1': {'unit': POWER_KILO_WATT, 'name': 'Power L1'},
        'p_l2': {'unit': POWER_KILO_WATT, 'name': 'Power L2'},
        'p_l3': {'unit': POWER_KILO_WATT, 'name': 'Power L3'},
        'p_n': {'unit': POWER_KILO_WATT, 'name': 'Power N'},
        'p_all': {'unit': POWER_KILO_WATT, 'name': 'Power All'},
        'current_session_charged_energy': {'unit': ENERGY_KILO_WATT_HOUR, 'name': 'Current Session charged'},
        'energy_total': {'unit': ENERGY_KILO_WATT_HOUR, 'name': 'Total Charged'},
        'charge_limit': {'unit': ENERGY_KILO_WATT_HOUR, 'name': 'Charge limit'},
        'u_l1': {'unit': VOLT, 'name': 'Voltage L1'},
        'u_l2': {'unit': VOLT, 'name': 'Voltage L2'},
        'u_l3': {'unit': VOLT, 'name': 'Voltage L3'},
        'u_n': {'unit': VOLT, 'name': 'Voltage N'},
        'i_l1': {'unit': AMPERE, 'name': 'Current L1'},
        'i_l2': {'unit': AMPERE, 'name': 'Current L2'},
        'i_l3': {'unit': AMPERE, 'name': 'Current L3'},
        'charger_max_current': {'unit': AMPERE, 'name': 'Charger max current setting'},
        'charger_absolute_max_current': {'unit': AMPERE, 'name': 'Charger absolute max current setting'},
        'cable_max_current': {'unit': AMPERE, 'name': 'Cable max current'},
        'unlocked_by_card': {'unit': CARD_ID, 'name': 'Card used'},
        'lf_l1': {'unit': PERCENT, 'name': 'Loadfactor L1'},
        'lf_l2': {'unit': PERCENT, 'name': 'Loadfactor L2'},
        'lf_l3': {'unit': PERCENT, 'name': 'Loadfactor L3'},
        'lf_n': {'unit': PERCENT, 'name': 'Loadfactor N'},
        'car_status': {'unit': '', 'name': 'Status'}
    }

    for sensor in hass.data[DOMAIN]:
        if sensor not in ('allow_charging', 'age'):
            _LOGGER.debug('adding Sensor: %s' % sensor)
            sensorUnit = sensorUnits.get(sensor).get('unit') if sensorUnits.get(sensor) else ''
            sensorName = sensorUnits.get(sensor).get('name') if sensorUnits.get(sensor) else sensor
            entities.append(
                GoeChargerSensor(
                    hass, goeCharger, f"sensor.goecharger_{serial}_{sensor}", sensorName, sensor, sensorUnit
                )
            )

    add_entities(entities)
Example #4
0
async def async_setup_entry(hass, config):
    _LOGGER.debug("async_Setup_entry")
    _LOGGER.debug(repr(config.data))

    name = config.data[CONF_NAME]
    charger = GoeCharger(config.data[CONF_HOST])
    hass.data[DOMAIN]["api"][name] = charger

    await hass.data[DOMAIN]["coordinator"].async_refresh()

    hass.async_create_task(
        hass.config_entries.async_forward_entry_setup(config, "sensor"))
    hass.async_create_task(
        hass.config_entries.async_forward_entry_setup(config, "switch"))
    return True
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up go-eCharger Switch platform."""
    if discovery_info is None:
        return

    serial = hass.data[DOMAIN]['serial_number']

    goeCharger = GoeCharger(discovery_info[CONF_HOST])

    attribute = 'allow_charging'
    add_entities(
        [
            GoeChargerSwitch(hass, goeCharger, f'switch.goecharger_{serial}_{attribute}', 'Charging allowed', attribute)
        ]
    )
Example #6
0
 def test_requestStatus(self, mock_get):
     status = GoeCharger('127.0.0.1').requestStatus()
     self.assertEqual(SAMPLE_REQUEST_STATUS_RESPONSE, status)
Example #7
0
#!/usr/bin/python

import sys
from datetime import datetime
from goecharger import (GoeCharger)

now = datetime.now()

goeCharger = GoeCharger('192.168.0.126')

status = goeCharger.requestStatus()
print("%s gerade geladen %.2fkWh    gesamt %.2fkWh mit %sA" %
      (now.strftime("%H:%M"), status['current_session_charged_energy'],
       status['energy_total'], status['charger_max_current']))

if len(sys.argv) == 2:
    current = int(sys.argv[-1])
    if current == 0:
        goeCharger.setAllowCharging(0)
        print("  Pausiere den Ladevorgang")
    else:
        goeCharger.setAllowCharging(1)
        status = goeCharger.setMaxCurrent(current)
        print("  %sA gesetzt, charger Temp=%sC" %
              (status['charger_max_current'], status['charger_temp']))
Example #8
0
 def test_create_with_host(self):
     self.assertIsNotNone(GoeCharger('127.0.0.1'))
Example #9
0
 def test_setAutoStopFalse(self, mock_get):
     response = GoeCharger('127.0.0.1').setAutoStop(False)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=stp=0')
     self.assertIsNotNone(response)
Example #10
0
 def test_setLedBrightnessToHigh(self, mock_get):
     response = GoeCharger('127.0.0.1').setLedBrightness(256)
     mock_get.assert_called_once_with(
         'http://127.0.0.1/mqtt?payload=lbr=255')
     self.assertIsNotNone(response)
Example #11
0
 def test_setMaxCurrentToLow(self, mock_get):
     response = GoeCharger('127.0.0.1').setMaxCurrent(5)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=amp=6')
     self.assertIsNotNone(response)
Example #12
0
 def test_setLedAutoTurnOffFalse(self, mock_get):
     response = GoeCharger('127.0.0.1').setLedAutoTurnOff(False)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=r2x=0')
     self.assertIsNotNone(response)
Example #13
0
 def test_setButtonCurrentValueToHigh(self, mock_get):
     response = GoeCharger('127.0.0.1').setButtonCurrentValue(1, 33)
     mock_get.assert_called_once_with(
         'http://127.0.0.1/mqtt?payload=al1=32')
     self.assertIsNotNone(response)
Example #14
0
 def test_setAccessType(self, mock_get):
     response = GoeCharger('127.0.0.1').setAccessType(
         GoeCharger.AccessType.FREE)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=ast=0')
     self.assertIsNotNone(response)
Example #15
0
#!/usr/bin/python3
# for this to work you need:
# - https://github.com/cathiele/goecharger
# - https://github.com/mchwalisz/pysenec
import sys
from goecharger import GoeCharger
import aiohttp
import pysenec
import asyncio
import logging
from pprint import pprint

logfile = '/var/www/html/pvload/pvload.log'

charger = GoeCharger('192.168.178.65')
senechost = '192.168.178.69'
logging.basicConfig(filename=(logfile),
                    format='%(asctime)s %(message)s',
                    level=logging.INFO)
if len(sys.argv) > 1:
    if str(sys.argv[1]) == "-v":
        verbose = True
    else:
        verbose = False
else:
    verbose = False

goestatus = charger.requestStatus()
if verbose:
    print("Actual Power: " + str(goestatus['charger_max_current']))
    print("Allow Charging: " + goestatus['allow_charging'])
def setup(hass, config):
    """Set up go-eCharger platforms and services."""

    # interval = config[DOMAIN].get(CONF_SCAN_INTERVAL)
    host = config[DOMAIN][CONF_HOST]
    serial = config[DOMAIN].get(CONF_SERIAL, "unknown")
    goeCharger = GoeCharger(host)
    status = goeCharger.requestStatus()

    if status.get("serial_number") == "unknown":
        status["serial_number"] = serial

    hass.data[DOMAIN] = status
    hass.data[DOMAIN]["age"] = utcnow().timestamp()

    def handle_set_max_current(call):
        """Handle the service call to set the absolute max current."""
        maxCurrentInput = call.data.get(
            SET_MAX_CURRENT_ATTR, hass.data[DOMAIN][ABSOLUTE_MAX_CURRENT])
        if isinstance(maxCurrentInput, str):
            if maxCurrentInput.isnumeric():
                maxCurrent = int(maxCurrentInput)
            elif valid_entity_id(maxCurrentInput):
                maxCurrent = int(hass.states.get(maxCurrentInput).state)
            else:
                _LOGGER.error("No valid value for '%s': %s",
                              SET_MAX_CURRENT_ATTR, maxCurrent)
                return
        else:
            maxCurrent = maxCurrentInput

        if maxCurrent < 6:
            maxCurrent = 6
        if maxCurrent > 32:
            maxCurrent = 32
        hass.data[DOMAIN] = goeCharger.setMaxCurrent(maxCurrent)
        hass.data[DOMAIN]["age"] = utcnow().timestamp()

    def handle_set_absolute_max_current(call):
        """Handle the service call to set the absolute max current."""
        absoluteMaxCurrentInput = call.data.get(SET_ABSOLUTE_MAX_CURRENT_ATTR,
                                                16)
        if isinstance(absoluteMaxCurrentInput, str):
            if absoluteMaxCurrentInput.isnumeric():
                absoluteMaxCurrent = int(absoluteMaxCurrentInput)
            elif valid_entity_id(absoluteMaxCurrentInput):
                absoluteMaxCurrent = int(
                    hass.states.get(absoluteMaxCurrentInput).state)
            else:
                _LOGGER.error(
                    "No valid value for '%s': %s",
                    SET_ABSOLUTE_MAX_CURRENT_ATTR,
                    absoluteMaxCurrentInput,
                )
                return
        else:
            absoluteMaxCurrent = absoluteMaxCurrentInput

        if absoluteMaxCurrent < 6:
            absoluteMaxCurrent = 6
        if absoluteMaxCurrent > 32:
            absoluteMaxCurrent = 32
        hass.data[DOMAIN] = goeCharger.setAbsoluteMaxCurrent(
            absoluteMaxCurrent)
        hass.data[DOMAIN]["age"] = utcnow().timestamp()

    def handle_set_cable_lock_mode(call):
        """Handle the service call to set the absolute max current."""
        cableLockModeInput = call.data.get(SET_CABLE_LOCK_MODE_ATTR, 0)
        if isinstance(cableLockModeInput, str):
            if cableLockModeInput.isnumeric():
                cableLockMode = int(cableLockModeInput)
            elif valid_entity_id(cableLockModeInput):
                cableLockMode = int(hass.states.get(cableLockModeInput).state)
            else:
                _LOGGER.error(
                    "No valid value for '%s': %s",
                    SET_CABLE_LOCK_MODE_ATTR,
                    cableLockModeInput,
                )
                return
        else:
            cableLockMode = cableLockModeInput

        cableLockModeEnum = GoeCharger.CableLockMode.UNLOCKCARFIRST
        if cableLockModeInput == 1:
            cableLockModeEnum = GoeCharger.CableLockMode.AUTOMATIC
        if cableLockMode >= 2:
            cableLockModeEnum = GoeCharger.CableLockMode.LOCKED

        hass.data[DOMAIN] = goeCharger.setCableLockMode(cableLockModeEnum)
        hass.data[DOMAIN]["age"] = utcnow().timestamp()

    def handle_set_charge_limit(call):
        """Handle the service call to set charge limit."""
        chargeLimitInput = call.data.get(CHARGE_LIMIT, 0.0)
        if isinstance(chargeLimitInput, str):
            if chargeLimitInput.isnumeric():
                chargeLimit = float(chargeLimitInput)
            elif valid_entity_id(chargeLimitInput):
                chargeLimit = float(hass.states.get(chargeLimitInput).state)
            else:
                _LOGGER.error("No valid value for '%s': %s", CHARGE_LIMIT,
                              chargeLimitInput)
                return
        else:
            chargeLimit = chargeLimitInput

        if chargeLimit < 0:
            chargeLimit = 0
        hass.data[DOMAIN] = goeCharger.setChargeLimit(chargeLimit)
        hass.data[DOMAIN]["age"] = utcnow().timestamp()

    hass.services.register(DOMAIN, "set_max_current", handle_set_max_current)
    hass.services.register(DOMAIN, "set_absolute_max_current",
                           handle_set_absolute_max_current)
    hass.services.register(DOMAIN, "set_cable_lock_mode",
                           handle_set_cable_lock_mode)
    hass.services.register(DOMAIN, "set_charge_limit", handle_set_charge_limit)

    hass.helpers.discovery.load_platform("sensor", DOMAIN, {CONF_HOST: host},
                                         config)
    hass.helpers.discovery.load_platform("switch", DOMAIN, {CONF_HOST: host},
                                         config)

    return True
Example #17
0
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
    """Set up go-eCharger platforms and services."""

    _LOGGER.debug("async_setup")
    scan_interval = DEFAULT_UPDATE_INTERVAL

    hass.data[DOMAIN] = {}
    chargerApi = {}
    chargers = []
    if DOMAIN in config:
        scan_interval = config[DOMAIN].get(CONF_SCAN_INTERVAL,
                                           DEFAULT_UPDATE_INTERVAL)

        host = config[DOMAIN].get(CONF_HOST, False)
        serial = config[DOMAIN].get(CONF_SERIAL, "unknown")

        chargers = config[DOMAIN].get(CONF_CHARGERS, [])

        if host:
            if not serial:
                goeCharger = GoeCharger(host)
                status = goeCharger.requestStatus()
                serial = status["serial_number"]
            chargers.append([{CONF_NAME: serial, CONF_HOST: host}])
        _LOGGER.debug(repr(chargers))

        for charger in chargers:
            chargerName = charger[0][CONF_NAME]
            host = charger[0][CONF_HOST]
            _LOGGER.debug(f"charger: '{chargerName}' host: '{host}' ")

            goeCharger = GoeCharger(host)
            chargerApi[chargerName] = goeCharger

    hass.data[DOMAIN]["api"] = chargerApi

    chargeStateFecher = ChargerStateFetcher(hass)

    coordinator = DataUpdateCoordinator(
        hass,
        _LOGGER,
        name=DOMAIN,
        update_method=chargeStateFecher.fetch_states,
        update_interval=scan_interval,
    )
    chargeStateFecher.coordinator = coordinator

    hass.data[DOMAIN]["coordinator"] = coordinator

    await coordinator.async_refresh()

    async def async_handle_set_max_current(call):
        """Handle the service call to set the absolute max current."""
        chargerNameInput = call.data.get(CHARGER_NAME_ATTR, '')

        maxCurrentInput = call.data.get(
            SET_MAX_CURRENT_ATTR,
            32  # TODO: dynamic based on chargers absolute_max-setting
        )
        maxCurrent = 0
        if isinstance(maxCurrentInput, str):
            if maxCurrentInput.isnumeric():
                maxCurrent = int(maxCurrentInput)
            elif valid_entity_id(maxCurrentInput):
                maxCurrent = int(hass.states.get(maxCurrentInput).state)
            else:
                _LOGGER.error("No valid value for '%s': %s",
                              SET_MAX_CURRENT_ATTR, maxCurrent)
                return
        else:
            maxCurrent = maxCurrentInput

        if maxCurrent < 6:
            maxCurrent = 6
        if maxCurrent > 32:
            maxCurrent = 32

        if len(chargerNameInput) > 0:
            _LOGGER.debug(
                f"set max_current for charger '{chargerNameInput}' to {maxCurrent}"
            )
            try:
                await hass.async_add_executor_job(
                    hass.data[DOMAIN]["api"]
                    [chargerNameInput].setTmpMaxCurrent, maxCurrent)
            except KeyError:
                _LOGGER.error(f"Charger with name '{chargerName}' not found!")

        else:
            for charger in hass.data[DOMAIN]["api"].keys():
                try:
                    _LOGGER.debug(
                        f"set max_current for charger '{charger}' to {maxCurrent}"
                    )
                    await hass.async_add_executor_job(
                        hass.data[DOMAIN]["api"][charger].setTmpMaxCurrent,
                        maxCurrent)
                except KeyError:
                    _LOGGER.error(
                        f"Charger with name '{chargerName}' not found!")

        await hass.data[DOMAIN]["coordinator"].async_refresh()

    async def async_handle_set_absolute_max_current(call):
        """Handle the service call to set the absolute max current."""
        chargerNameInput = call.data.get(CHARGER_NAME_ATTR, '')
        absoluteMaxCurrentInput = call.data.get(SET_ABSOLUTE_MAX_CURRENT_ATTR,
                                                16)
        if isinstance(absoluteMaxCurrentInput, str):
            if absoluteMaxCurrentInput.isnumeric():
                absoluteMaxCurrent = int(absoluteMaxCurrentInput)
            elif valid_entity_id(absoluteMaxCurrentInput):
                absoluteMaxCurrent = int(
                    hass.states.get(absoluteMaxCurrentInput).state)
            else:
                _LOGGER.error(
                    "No valid value for '%s': %s",
                    SET_ABSOLUTE_MAX_CURRENT_ATTR,
                    absoluteMaxCurrentInput,
                )
                return
        else:
            absoluteMaxCurrent = absoluteMaxCurrentInput

        if absoluteMaxCurrent < 6:
            absoluteMaxCurrent = 6
        if absoluteMaxCurrent > 32:
            absoluteMaxCurrent = 32

        if len(chargerNameInput) > 0:
            _LOGGER.debug(
                f"set absolute_max_current for charger '{chargerNameInput}' to {absoluteMaxCurrent}"
            )
            try:
                await hass.async_add_executor_job(
                    hass.data[DOMAIN]["api"]
                    [chargerNameInput].setAbsoluteMaxCurrent,
                    absoluteMaxCurrent)
            except KeyError:
                _LOGGER.error(f"Charger with name '{chargerName}' not found!")

        else:
            for charger in hass.data[DOMAIN]["api"].keys():
                try:
                    _LOGGER.debug(
                        f"set absolute_max_current for charger '{charger}' to {absoluteMaxCurrent}"
                    )
                    await hass.async_add_executor_job(
                        hass.data[DOMAIN]["api"]
                        [charger].setAbsoluteMaxCurrent, absoluteMaxCurrent)
                except KeyError:
                    _LOGGER.error(
                        f"Charger with name '{chargerName}' not found!")

        await hass.data[DOMAIN]["coordinator"].async_refresh()

    async def async_handle_set_cable_lock_mode(call):
        """Handle the service call to set the absolute max current."""
        chargerNameInput = call.data.get(CHARGER_NAME_ATTR, '')
        cableLockModeInput = call.data.get(SET_CABLE_LOCK_MODE_ATTR, 0)
        if isinstance(cableLockModeInput, str):
            if cableLockModeInput.isnumeric():
                cableLockMode = int(cableLockModeInput)
            elif valid_entity_id(cableLockModeInput):
                cableLockMode = int(hass.states.get(cableLockModeInput).state)
            else:
                _LOGGER.error(
                    "No valid value for '%s': %s",
                    SET_CABLE_LOCK_MODE_ATTR,
                    cableLockModeInput,
                )
                return
        else:
            cableLockMode = cableLockModeInput

        cableLockModeEnum = GoeCharger.CableLockMode.UNLOCKCARFIRST
        if cableLockModeInput == 1:
            cableLockModeEnum = GoeCharger.CableLockMode.AUTOMATIC
        if cableLockMode >= 2:
            cableLockModeEnum = GoeCharger.CableLockMode.LOCKED

        if len(chargerNameInput) > 0:
            _LOGGER.debug(
                f"set set_cable_lock_mode for charger '{chargerNameInput}' to {cableLockModeEnum}"
            )
            try:
                await hass.async_add_executor_job(
                    hass.data[DOMAIN]["api"]
                    [chargerNameInput].setCableLockMode, cableLockModeEnum)
            except KeyError:
                _LOGGER.error(f"Charger with name '{chargerName}' not found!")

        else:
            for charger in hass.data[DOMAIN]["api"].keys():
                try:
                    _LOGGER.debug(
                        f"set set_cable_lock_mode for charger '{charger}' to {cableLockModeEnum}"
                    )
                    await hass.async_add_executor_job(
                        hass.data[DOMAIN]["api"][charger].setCableLockMode,
                        cableLockModeEnum)
                except KeyError:
                    _LOGGER.error(
                        f"Charger with name '{chargerName}' not found!")

        await hass.data[DOMAIN]["coordinator"].async_refresh()

    async def async_handle_set_charge_limit(call):
        """Handle the service call to set charge limit."""
        chargerNameInput = call.data.get(CHARGER_NAME_ATTR, '')
        chargeLimitInput = call.data.get(CHARGE_LIMIT, 0.0)
        if isinstance(chargeLimitInput, str):
            if chargeLimitInput.isnumeric():
                chargeLimit = float(chargeLimitInput)
            elif valid_entity_id(chargeLimitInput):
                chargeLimit = float(hass.states.get(chargeLimitInput).state)
            else:
                _LOGGER.error("No valid value for '%s': %s", CHARGE_LIMIT,
                              chargeLimitInput)
                return
        else:
            chargeLimit = chargeLimitInput

        if chargeLimit < 0:
            chargeLimit = 0

        if len(chargerNameInput) > 0:
            _LOGGER.debug(
                f"set set_charge_limit for charger '{chargerNameInput}' to {chargeLimit}"
            )
            try:
                await hass.async_add_executor_job(
                    hass.data[DOMAIN]["api"][chargerNameInput].setChargeLimit,
                    chargeLimit)
            except KeyError:
                _LOGGER.error(f"Charger with name '{chargerName}' not found!")

        else:
            for charger in hass.data[DOMAIN]["api"].keys():
                try:
                    _LOGGER.debug(
                        f"set set_charge_limit for charger '{charger}' to {chargeLimit}"
                    )
                    await hass.async_add_executor_job(
                        hass.data[DOMAIN]["api"][charger].setChargeLimit,
                        chargeLimit)
                except KeyError:
                    _LOGGER.error(
                        f"Charger with name '{chargerName}' not found!")

        await hass.data[DOMAIN]["coordinator"].async_refresh()

    hass.services.async_register(DOMAIN, "set_max_current",
                                 async_handle_set_max_current)
    hass.services.async_register(DOMAIN, "set_absolute_max_current",
                                 async_handle_set_absolute_max_current)
    hass.services.async_register(DOMAIN, "set_cable_lock_mode",
                                 async_handle_set_cable_lock_mode)
    hass.services.async_register(DOMAIN, "set_charge_limit",
                                 async_handle_set_charge_limit)

    hass.async_create_task(
        async_load_platform(hass, "sensor", DOMAIN, {
            CONF_CHARGERS: chargers,
            CHARGER_API: chargerApi
        }, config))
    hass.async_create_task(
        async_load_platform(hass, "switch", DOMAIN, {
            CONF_CHARGERS: chargers,
            CHARGER_API: chargerApi
        }, config))

    return True
Example #18
0
 def test_setCableLockMode(self, mock_get):
     response = GoeCharger('127.0.0.1').setCableLockMode(
         GoeCharger.CableLockMode.AUTOMATIC)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=ust=1')
     self.assertIsNotNone(response)
Example #19
0
def setup(hass, config):
    """Set up go-eCharger platforms and services."""

    # interval = config[DOMAIN].get(CONF_SCAN_INTERVAL)
    host = config[DOMAIN][CONF_HOST]
    serial = config[DOMAIN].get(CONF_SERIAL, 'unknown')
    goeCharger = GoeCharger(host)
    status = goeCharger.requestStatus()

    if status.get('serial_number') == 'unknown':
        status['serial_number'] = serial

    hass.data[DOMAIN] = status
    hass.data[DOMAIN]['age'] = utcnow().timestamp()

    def handle_set_max_current(call):
        """Handle the service call."""
        maxCurrent = call.data.get(SET_MAX_CURRENT_ATTR,
                                   hass.data[DOMAIN][ABSOLUTE_MAX_CURRENT])
        if isinstance(maxCurrent, str):
            maxCurrent = int(maxCurrent)

        if maxCurrent < 6:
            maxCurrent = 6
        if maxCurrent > 32:
            maxCurrent = 32
        hass.data[DOMAIN] = goeCharger.setMaxCurrent(maxCurrent)
        hass.data[DOMAIN]['age'] = utcnow().timestamp()

    def handle_set_absolute_max_current(call):
        """Handle the service call."""
        absoluteMaxCurrent = call.data.get(SET_ABSOLUTE_MAX_CURRENT_ATTR, 16)
        if isinstance(absoluteMaxCurrent, str):
            absoluteMaxCurrent = int(absoluteMaxCurrent)

        if absoluteMaxCurrent < 6:
            absoluteMaxCurrent = 6
        if absoluteMaxCurrent > 32:
            absoluteMaxCurrent = 32
        hass.data[DOMAIN] = goeCharger.setAbsoluteMaxCurrent(
            absoluteMaxCurrent)
        hass.data[DOMAIN]['age'] = utcnow().timestamp()

    def handle_set_charge_limit(call):
        """Handle the service call."""
        chargeLimit = call.data.get(CHARGE_LIMIT, 0.0)
        if isinstance(chargeLimit, str):
            chargeLimit = float(chargeLimit)

        if chargeLimit < 0:
            chargeLimit = 0
        hass.data[DOMAIN] = goeCharger.setChargeLimit(chargeLimit)
        hass.data[DOMAIN]['age'] = utcnow().timestamp()

    hass.services.register(DOMAIN, 'set_max_current', handle_set_max_current)
    hass.services.register(DOMAIN, 'set_absolute_max_current',
                           handle_set_absolute_max_current)
    hass.services.register(DOMAIN, 'set_charge_limit', handle_set_charge_limit)

    hass.helpers.discovery.load_platform('sensor', DOMAIN, {CONF_HOST: host},
                                         config)
    hass.helpers.discovery.load_platform('switch', DOMAIN, {CONF_HOST: host},
                                         config)

    return True
Example #20
0
 def test_setChargeLimit(self, mock_get):
     response = GoeCharger('127.0.0.1').setChargeLimit(2.4)
     mock_get.assert_called_once_with(
         'http://127.0.0.1/mqtt?payload=dwo=24')
     self.assertIsNotNone(response)
Example #21
0
def helper_create_instance_without_host():
    return GoeCharger(None)
Example #22
0
 def test_setAbsoluteMaxCurrentToHigh(self, mock_get):
     response = GoeCharger('127.0.0.1').setAbsoluteMaxCurrent(33)
     mock_get.assert_called_once_with(
         'http://127.0.0.1/mqtt?payload=ama=32')
     self.assertIsNotNone(response)
Example #23
0
def helper_setButtonCurrentValue_ValueError():
    return GoeCharger('http://127.0.0.1').setButtonCurrentValue(0, 6)
Example #24
0
 def test_setAllowChargingFalse(self, mock_get):
     response = GoeCharger('127.0.0.1').setAllowCharging(False)
     mock_get.assert_called_once_with('http://127.0.0.1/mqtt?payload=alw=0')
     self.assertIsNotNone(response)
Example #25
0
def helper_setAccessType_ValueError():
    return GoeCharger('http://127.0.0.1').setAccessType(1111)
Example #26
0
 def test_setChargingFinishedColor(self, mock_get):
     response = GoeCharger('127.0.0.1').setChargingFinishedColor(0x808080)
     mock_get.assert_called_once_with(
         'http://127.0.0.1/mqtt?payload=cfi=8421504')
     self.assertIsNotNone(response)
Example #27
0
def helper_setCableLockMode_ValueError():
    return GoeCharger('http://127.0.0.1').setCableLockMode(1111)
Example #28
0
 def test_chargerNotAvailable(self):
     status = GoeCharger('127.0.0.2').requestStatus()
     self.maxDiff = None
     self.assertEqual(SAMPLE_REQUEST_STATUS_RESPONSE_UNAVAIL, status)
Example #29
0
                    help="Do not use more ampere for charging",
                    type=int,
                    default=22)
parser.add_argument("-k",
                    "--keep_charging",
                    help="Dont stop charging, usfull if car cant be woken up",
                    action="store_true")
parser.add_argument("-v",
                    "--verbose",
                    help="increase output verbosity",
                    action="store_true")
args = parser.parse_args()

DBusGMainLoop(set_as_default=True)

goeCharger = GoeCharger(GOE_IP)

dbusConn = dbus.SystemBus()


def cleanup(*args):
    if iGoe > 20:
        # Besser fuer die Sicherung:
        print("Stelle Goe auf 15 Ampere ... Warte 10s")
        goeCharger.setMaxCurrent(15)
        time.sleep(10)

    os._exit(0)

    if iGoe > 14:
        # Besser fuer die Sicherung: