def get_vehicle(parsed_args): k = Kamereon() vehicles = k.get_vehicles().get('vehicleLinks') if parsed_args.vin: possible_vehicles = [v for v in vehicles if v['vin'] == parsed_args.vin] if len(possible_vehicles) == 0: raise RuntimeError('Specified VIN {} not found! Use `pyze vehicles` to list available vehicles.'.format(parsed_args.vin)) vin = possible_vehicles[0]['vin'] elif parsed_args.reg: possible_vehicles = [v for v in vehicles if v['vehicleDetails']['registrationNumber'] == parsed_args.vin.replace(' ', '').upper()][0] if len(possible_vehicles) == 0: raise RuntimeError('Specified registration plate {} not found! Use `pyze vehicles` to list available vehicles.'.format(parsed_args.reg)) vin = possible_vehicles[0]['vin'] elif len(vehicles) == 0: raise RuntimeError('No vehicles found for this account!') else: vin = vehicles[0]['vin'] return Vehicle(vin, k)
def __init__(self): file_path = os.path.dirname(__file__) if file_path != "": os.chdir(file_path) with open('config.yml', 'r') as ymlfile: self.config = yaml.load(ymlfile, Loader=yaml.FullLoader) self.cache = FileCache('zoe-domoticz', flag='cs') self.domoticz = Domoticz(self.config) # PyZE stuff: self.gigya = Gigya() self.login() self.kamereon = Kamereon(gigya=self.gigya, country=self.config['myRenaultCountry']) self.vehicle = Vehicle(self.config['myRenaultVIN'], self.kamereon)
async def get_vehicle_proxy(self, vehicle_link: dict): """Get a pyze proxy for the vehicle. Using lock to ensure vehicle proxies are only created once across all platforms. """ vin: str = vehicle_link["vin"] vin = vin.upper() async with self._vehicles_lock: pyze_vehicle_proxy = self._vehicle_proxies.get(vin) if pyze_vehicle_proxy is None: pyze_vehicle_proxy = PyzeVehicleProxy( self._hass, vehicle_link, Vehicle(vehicle_link["vin"], self._kamereon), ) self._vehicle_proxies[vin] = pyze_vehicle_proxy await pyze_vehicle_proxy.async_initialise return self._vehicle_proxies[vin]
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Setup the sensor platform.""" _LOGGER.debug("Initialising renaultze platform") g_url = None g_key = None k_url = None k_key = None k_account_id = config.get(CONF_K_ACCOUNTID, '') cred = CredentialStore() cred.clear() url = 'https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_%s.json' % config.get( CONF_ANDROID_LNG) async with aiohttp.ClientSession() as session: async with session.get(url) as response: responsetext = await response.text() if responsetext == '': responsetext = '{}' jsonresponse = json.loads(responsetext) g_url = jsonresponse['servers']['gigyaProd']['target'] g_key = jsonresponse['servers']['gigyaProd']['apikey'] k_url = jsonresponse['servers']['wiredProd']['target'] k_key = jsonresponse['servers']['wiredProd']['apikey'] g = Gigya(api_key=g_key, root_url=g_url) if not g.login(config.get(CONF_USERNAME), config.get(CONF_PASSWORD)): raise RenaultZEError("Login failed") g.account_info() k = Kamereon(api_key=k_key, root_url=k_url, gigya=g) if k_account_id != '': k.set_account_id(k_account_id) v = Vehicle(config.get(CONF_VIN), k) devices = [RenaultZESensor(v, config.get(CONF_NAME, config.get(CONF_VIN)))] async_add_entities(devices)
class Main: def __init__(self): file_path = os.path.dirname(__file__) if file_path != "": os.chdir(file_path) with open('config.yml', 'r') as ymlfile: self.config = yaml.load(ymlfile, Loader=yaml.FullLoader) self.cache = FileCache('zoe-domoticz', flag='cs') self.domoticz = Domoticz(self.config) # PyZE stuff: self.gigya = Gigya() self.login() self.kamereon = Kamereon(gigya=self.gigya, country=self.config['myRenaultCountry']) self.vehicle = Vehicle(self.config['myRenaultVIN'], self.kamereon) def login(self): # Login only needs to be called once and credentials are cached by pyze (?) self.gigya.login(self.config['myRenaultEmail'], self.config['myRenaultPassword']) self.gigya.account_info() # Retrieves and caches person ID def updateDomoticz(self, batt, hvac, mileage): print("Updating data in Domoticz...\n") dz = self.domoticz config = self.config plugged_in, charging = batt['plugStatus'] > 0, batt['chargeStatus'] > 0 if charging: dz.setPower(config['dzChargePowerId'], batt['instantaneousPower']) else: dz.setPower(config['dzChargePowerId'], 0) dz.setValue(config['dzBatteryPercentageId'], batt['batteryLevel']) dz.setValue(config['dzRangeId'], batt['rangeHvacOff']) dz.setValue(config['dzBatteryTempId'], batt['batteryTemperature']) dz.setValue(config['dzExternalTempId'], hvac['externalTemperature']) dz.setValue(config['dzMileageId'], mileage['totalMileage']) dz.setSwitch(config['dzPlugStateId'], plugged_in) print("Update success!") def execute(self): cache = self.cache batt = self.vehicle.battery_status() hvac = self.vehicle.hvac_status() mileage = self.vehicle.mileage() if self.config['debug'] == True: self.printDebugInfo(batt, hvac, mileage) if 'lastUpdateTime' in cache: lastUpdateTime = cache['lastUpdateTime'] else: lastUpdateTime = 'never' if batt['lastUpdateTime'] != lastUpdateTime: print("Last update at: %s, updating!" % lastUpdateTime) cache['lastUpdateTime'] = batt['lastUpdateTime'] self.updateDomoticz(batt, hvac, mileage) else: print("Last update at %s, skipping update." % lastUpdateTime) def printDebugInfo(self, batt, hvac, mileage): print("Battery Status:") print(batt) # When plugged in and charging: # {'rangeHvacOff': 134, 'plugStatus': 1, 'chargePower': 1, 'lastUpdateTime': '2019-10-20T10:33:48+02:00', # 'batteryTemperature': 16, 'chargeStatus': 1, 'batteryLevel': 99, 'instantaneousPower': 1600} # When plugged in and not charging: # {'plugStatus': 1, 'lastUpdateTime': '2019-10-20T11:07:04+02:00', 'batteryTemperature': 15, # 'chargeStatus': -1, 'batteryLevel': 100, 'rangeHvacOff': 137} print("\nHVAC Status:") print(hvac) # {'hvacStatus': 'off', 'externalTemperature': 10.0} print("\nMileage:") print(mileage)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Setup the sensor platform.""" _LOGGER.debug("Initialising renaultze platform") g_url = None g_key = None k_url = None k_key = None k_account_id = config.get(CONF_K_ACCOUNTID, '') cred = CredentialStore() cred.clear() url = 'https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_{0}.json'.format( config.get(CONF_ANDROID_LNG)) async with aiohttp.ClientSession() as session: async with session.get(url) as response: responsetext = await response.text() if responsetext == '': responsetext = '{}' jsonresponse = json.loads(responsetext) g_url = jsonresponse['servers']['gigyaProd']['target'] g_key = jsonresponse['servers']['gigyaProd']['apikey'] k_url = jsonresponse['servers']['wiredProd']['target'] k_key = jsonresponse['servers']['wiredProd']['apikey'] g = Gigya(api_key=g_key, root_url=g_url) if not g.login(config.get(CONF_USERNAME), config.get(CONF_PASSWORD)): raise RenaultZEError("Login failed") g.account_info() k = Kamereon(api_key=k_key, root_url=k_url, gigya=g) if k_account_id != '': k.set_account_id(k_account_id) v = Vehicle(config.get(CONF_VIN), k) devices = [RenaultZESensor(v, config.get(CONF_NAME, config.get(CONF_VIN)))] async_add_entities(devices) platform = entity_platform.current_platform.get() platform.async_register_entity_service( SERVICE_AC_START, { vol.Optional(ATTR_WHEN): cv.datetime, vol.Optional(ATTR_TEMPERATURE): cv.positive_int, }, "ac_start", ) platform.async_register_entity_service( SERVICE_AC_CANCEL, {}, "ac_cancel", ) platform.async_register_entity_service( SERVICE_CHARGE_START, {}, "charge_start", ) platform.async_register_entity_service( SERVICE_CHARGE_SET_MODE, { vol.Required(ATTR_CHARGE_MODE): cv.enum(ChargeMode), }, "charge_set_mode", ) platform.async_register_entity_service( SERVICE_CHARGE_SET_SCHEDULES, { vol.Required(ATTR_SCHEDULES): dict, }, "charge_set_schedules", )
from pyze.api import Gigya, Kamereon, Vehicle import json import sys from prtg.sensor.result import CustomSensorResult from prtg.sensor.units import ValueUnit g = Gigya() g.set_api_key( '3_e8d4g4SE_Fo8ahyHwwP7ohLGZ79HKNN2T8NjQqoNnk6Epj6ilyYwKdHUyCw3wuxz') g.login('email', 'password') g.account_info() k = Kamereon(gigya=g) k.set_api_key('Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2') v = Vehicle('VIN', k) data = v.battery_status() data_hvac = v.hvac_status() sensor = CustomSensorResult() sensor.add_channel(name='Battery Percentage', unit='Percent', value=data['batteryLevel']) sensor.add_channel(name='Range', unit='KM', value=data['batteryAutonomy']) sensor.add_channel(name='External Temperature', unit='Temperature', value=data_hvac['externalTemperature']) sensor.add_channel(name='Plugged In', value=data['plugStatus']) sensor.add_channel(name='Charging Status', value=data['chargingStatus']) print(sensor.json_result)