<commit_before>//
//  ClimateState.swift
//  TeslaSwift
//
//  Created by <NAME> on 14/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

open class ClimateState: Codable {
	
	open var batteryHeater: Bool?
	
	open var batteryHeaterNoPower: Bool?
	
	public struct Temperature: Codable {
		public var value: Measurement<UnitTemperature>
		
		public init(celsius: Double?) {
			let tempValue = celsius ?? 0.0
			value = Measurement<UnitTemperature>(value: tempValue, unit: .celsius)
		}
		public init(fahrenheit: Double) {
			value = Measurement<UnitTemperature>(value: fahrenheit, unit: .fahrenheit)
		}
		
		public init(from decoder: Decoder) throws {
			let container = try decoder.singleValueContainer()
			if let tempValue = try container.decode(Double?.self) {
				value = Measurement<UnitTemperature>(value: tempValue, unit: .celsius)
			} else {
				value = Measurement<UnitTemperature>(value: 0, unit: .celsius)
			}
		}
		
		public func encode(to encoder: Encoder) throws {
			
			var container = encoder.singleValueContainer()
			try container.encode(value.converted(to: .celsius).value)
			
		}
		
		public var celsius: Double { return value.converted(to: .celsius).value }
		public var fahrenheit: Double { return value.converted(to: .fahrenheit).value }
	}
	
	open var driverTemperatureSetting: Temperature?
	/*
	* Fan speed 0-6 or nil
	*/
	open var fanStatus: Int?
	
	open var insideTemperature: Temperature?
	
	open var isAutoConditioningOn: Bool?
	open var isClimateOn: Bool?
	open var isFrontDefrosterOn: Bool?
	open var isRearDefrosterOn: Bool?
	
	open var isPreconditioning: Bool?
	
	open var leftTemperatureDirection: Int?
	
	open var maxAvailableTemperature: Temperature?
	open var minAvailableTemperature: Temperature?
	
	open var outsideTemperature: Temperature?
	
	open var passengerTemperatureSetting: Temperature?
	
	/*
	* Temp directions 0 at least 583...
	*/
	open var rightTemperatureDirection: Int?
	
	
    open var seatHeaterLeft: Bool?
	open var seatHeaterRearCenter: Bool?
	open var seatHeaterRearLeft: Bool?
	open var seatHeaterRearLeftBack: Int?
	open var seatHeaterRearRight: Bool?
	open var seatHeaterRearRightBack: Int?
	open var seatHeaterRight: Bool?
	
	open var sideMirrorHeaters: Bool?
	open var steeringWheelHeater: Bool?
	open var wiperBladeHeater: Bool?
	
	open var smartPreconditioning: Bool?
	
	open var timeStamp: Double?
	
	enum CodingKeys: String, CodingKey {
		
		case batteryHeater   = "battery_heater"
		case batteryHeaterNoPower = "battery_heater_no_power"
		
		case driverTemperatureSetting	= "driver_temp_setting"
		case fanStatus					 = "fan_status"
		
		case insideTemperature			= "inside_temp"
		
		case isAutoConditioningOn		 = "is_auto_conditioning_on"
		case isClimateOn	             = "is_climate_on"
		case isFrontDefrosterOn			 = "is_front_defroster_on"
		case isRearDefrosterOn			 = "is_rear_defroster_on"
		
		case isPreconditioning		= "is_preconditioning"
		
		case leftTemperatureDirection	 = "left_temp_direction"
		
		case maxAvailableTemperature     = "max_avail_temp"
		case minAvailableTemperature     = "min_avail_temp"
		
		case outsideTemperature			= "outside_temp"
		
		case passengerTemperatureSetting = "passenger_temp_setting"
		
		case rightTemperatureDirection	 = "right_temp_direction"
		
		
        case seatHeaterLeft				 = "seat_heater_left"
		case seatHeaterRearCenter		 = "seat_heater_rear_center"
		case seatHeaterRearLeft			 = "seat_heater_rear_left"
		case seatHeaterRearLeftBack		 = "seat_heater_rear_left_back"
		case seatHeaterRearRight			 = "seat_heater_rear_right"
		case seatHeaterRearRightBack		 = "seat_heater_rear_right_back"
		case seatHeaterRight				 = "seat_heater_right"
		
		case sideMirrorHeaters				= "side_mirror_heaters"
		case steeringWheelHeater			= "steering_wheel_heater"
		case wiperBladeHeater				= "wiper_blade_heater"
		
        case smartPreconditioning		 = "smart_preconditioning"
		
		case timeStamp					= "timestamp"
        
	}
	
	required public init(from decoder: Decoder) throws {
		
		let container = try decoder.container(keyedBy: CodingKeys.self)
		
		batteryHeater = try? container.decode(Bool.self, forKey: .batteryHeater)
		
		batteryHeaterNoPower = try? container.decode(Bool.self, forKey: .batteryHeaterNoPower)
		
		driverTemperatureSetting = try? container.decode(Temperature.self, forKey: .driverTemperatureSetting)
	
		fanStatus = try? container.decode(Int.self, forKey: .fanStatus)
		
		insideTemperature  = try? container.decode(Temperature.self, forKey: .insideTemperature)
		
		isAutoConditioningOn  = try? container.decode(Bool.self, forKey: .isAutoConditioningOn)
		isClimateOn  = try? container.decode(Bool.self, forKey: .isClimateOn)
		isFrontDefrosterOn  = try? container.decode(Bool.self, forKey: .isFrontDefrosterOn)
		isRearDefrosterOn  = try? container.decode(Bool.self, forKey: .isRearDefrosterOn)
		
		isPreconditioning  = try? container.decode(Bool.self, forKey: .isPreconditioning)
		
		leftTemperatureDirection  = try? container.decode(Int.self, forKey: .leftTemperatureDirection)
		
		maxAvailableTemperature  = try? container.decode(Temperature.self, forKey: .maxAvailableTemperature)
		minAvailableTemperature  = try? container.decode(Temperature.self, forKey: .minAvailableTemperature)
		
		outsideTemperature  = try? container.decode(Temperature.self, forKey: .outsideTemperature)
		
		passengerTemperatureSetting  = try? container.decode(Temperature.self, forKey: .passengerTemperatureSetting)
		

		rightTemperatureDirection  = try? container.decode(Int.self, forKey: .rightTemperatureDirection)
		
		
		seatHeaterLeft  = try? container.decode(Bool.self, forKey: .seatHeaterLeft)
		seatHeaterRearCenter  = try? container.decode(Bool.self, forKey: .seatHeaterRearCenter)
		seatHeaterRearLeft  = try? container.decode(Bool.self, forKey: .seatHeaterRearLeft)
		seatHeaterRearLeftBack  = try? container.decode(Int.self, forKey: .seatHeaterRearLeftBack)
		seatHeaterRearRight  = try? container.decode(Bool.self, forKey: .seatHeaterRearRight)
		seatHeaterRearRightBack  = try? container.decode(Int.self, forKey: .seatHeaterRearRightBack)
		seatHeaterRight  = try? container.decode(Bool.self, forKey: .seatHeaterRight)
		
		sideMirrorHeaters  = try? container.decode(Bool.self, forKey: .sideMirrorHeaters)
		steeringWheelHeater  = try? container.decode(Bool.self, forKey: .steeringWheelHeater)<commit_msg>Changed Bool to Int for Seat heaters<commit_after>//
//  ClimateState.swift
//  TeslaSwift
//
//  Created by <NAME> on 14/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

open class ClimateState: Codable {
	
	open var batteryHeater: Bool?
	
	open var batteryHeaterNoPower: Bool?
	
	public struct Temperature: Codable {
		public var value: Measurement<UnitTemperature>
		
		public init(celsius: Double?) {
			let tempValue = celsius ?? 0.0
			value = Measurement<UnitTemperature>(value: tempValue, unit: .celsius)
		}
		public init(fahrenheit: Double) {
			value = Measurement<UnitTemperature>(value: fahrenheit, unit: .fahrenheit)
		}
		
		public init(from decoder: Decoder) throws {
			let container = try decoder.singleValueContainer()
			if let tempValue = try container.decode(Double?.self) {
				value = Measurement<UnitTemperature>(value: tempValue, unit: .celsius)
			} else {
				value = Measurement<UnitTemperature>(value: 0, unit: .celsius)
			}
		}
		
		public func encode(to encoder: Encoder) throws {
			
			var container = encoder.singleValueContainer()
			try container.encode(value.converted(to: .celsius).value)
			
		}
		
		public var celsius: Double { return value.converted(to: .celsius).value }
		public var fahrenheit: Double { return value.converted(to: .fahrenheit).value }
	}
	
	open var driverTemperatureSetting: Temperature?
	/*
	* Fan speed 0-6 or nil
	*/
	open var fanStatus: Int?
	
	open var insideTemperature: Temperature?
	
	open var isAutoConditioningOn: Bool?
	open var isClimateOn: Bool?
	open var isFrontDefrosterOn: Bool?
	open var isRearDefrosterOn: Bool?
	
	open var isPreconditioning: Bool?
	
	open var leftTemperatureDirection: Int?
	
	open var maxAvailableTemperature: Temperature?
	open var minAvailableTemperature: Temperature?
	
	open var outsideTemperature: Temperature?
	
	open var passengerTemperatureSetting: Temperature?
	
	/*
	* Temp directions 0 at least 583...
	*/
	open var rightTemperatureDirection: Int?
	
	
    open var seatHeaterLeft: Int?
	open var seatHeaterRearCenter: Int?
	open var seatHeaterRearLeft: Int?
	open var seatHeaterRearLeftBack: Int?
	open var seatHeaterRearRight: Int?
	open var seatHeaterRearRightBack: Int?
	open var seatHeaterRight: Int?
	
	open var sideMirrorHeaters: Bool?
	open var steeringWheelHeater: Bool?
	open var wiperBladeHeater: Bool?
	
	open var smartPreconditioning: Bool?
	
	open var timeStamp: Double?
	
	enum CodingKeys: String, CodingKey {
		
		case batteryHeater   = "battery_heater"
		case batteryHeaterNoPower = "battery_heater_no_power"
		
		case driverTemperatureSetting	= "driver_temp_setting"
		case fanStatus					 = "fan_status"
		
		case insideTemperature			= "inside_temp"
		
		case isAutoConditioningOn		 = "is_auto_conditioning_on"
		case isClimateOn	             = "is_climate_on"
		case isFrontDefrosterOn			 = "is_front_defroster_on"
		case isRearDefrosterOn			 = "is_rear_defroster_on"
		
		case isPreconditioning		= "is_preconditioning"
		
		case leftTemperatureDirection	 = "left_temp_direction"
		
		case maxAvailableTemperature     = "max_avail_temp"
		case minAvailableTemperature     = "min_avail_temp"
		
		case outsideTemperature			= "outside_temp"
		
		case passengerTemperatureSetting = "passenger_temp_setting"
		
		case rightTemperatureDirection	 = "right_temp_direction"
		
		
        case seatHeaterLeft				 = "seat_heater_left"
		case seatHeaterRearCenter		 = "seat_heater_rear_center"
		case seatHeaterRearLeft			 = "seat_heater_rear_left"
		case seatHeaterRearLeftBack		 = "seat_heater_rear_left_back"
		case seatHeaterRearRight			 = "seat_heater_rear_right"
		case seatHeaterRearRightBack		 = "seat_heater_rear_right_back"
		case seatHeaterRight				 = "seat_heater_right"
		
		case sideMirrorHeaters				= "side_mirror_heaters"
		case steeringWheelHeater			= "steering_wheel_heater"
		case wiperBladeHeater				= "wiper_blade_heater"
		
        case smartPreconditioning		 = "smart_preconditioning"
		
		case timeStamp					= "timestamp"
        
	}
	
	required public init(from decoder: Decoder) throws {
		
		let container = try decoder.container(keyedBy: CodingKeys.self)
		
		batteryHeater = try? container.decode(Bool.self, forKey: .batteryHeater)
		
		batteryHeaterNoPower = try? container.decode(Bool.self, forKey: .batteryHeaterNoPower)
		
		driverTemperatureSetting = try? container.decode(Temperature.self, forKey: .driverTemperatureSetting)
	
		fanStatus = try? container.decode(Int.self, forKey: .fanStatus)
		
		insideTemperature  = try? container.decode(Temperature.self, forKey: .insideTemperature)
		
		isAutoConditioningOn  = try? container.decode(Bool.self, forKey: .isAutoConditioningOn)
		isClimateOn  = try? container.decode(Bool.self, forKey: .isClimateOn)
		isFrontDefrosterOn  = try? container.decode(Bool.self, forKey: .isFrontDefrosterOn)
		isRearDefrosterOn  = try? container.decode(Bool.self, forKey: .isRearDefrosterOn)
		
		isPreconditioning  = try? container.decode(Bool.self, forKey: .isPreconditioning)
		
		leftTemperatureDirection  = try? container.decode(Int.self, forKey: .leftTemperatureDirection)
		
		maxAvailableTemperature  = try? container.decode(Temperature.self, forKey: .maxAvailableTemperature)
		minAvailableTemperature  = try? container.decode(Temperature.self, forKey: .minAvailableTemperature)
		
		outsideTemperature  = try? container.decode(Temperature.self, forKey: .outsideTemperature)
		
		passengerTemperatureSetting  = try? container.decode(Temperature.self, forKey: .passengerTemperatureSetting)
		

		rightTemperatureDirection  = try? container.decode(Int.self, forKey: .rightTemperatureDirection)
		
		
		seatHeaterLeft  = try? container.decode(Int.self, forKey: .seatHeaterLeft)
		seatHeaterRearCenter  = try? container.decode(Int.self, forKey: .seatHeaterRearCenter)
		seatHeaterRearLeft  = try? container.decode(Int.self, forKey: .seatHeaterRearLeft)
		seatHeaterRearLeftBack  = try? container.decode(Int.self, forKey: .seatHeaterRearLeftBack)
		seatHeaterRearRight  = try? container.decode(Int.self, forKey: .seatHeaterRearRight)
		seatHeaterRearRightBack  = try? container.decode(Int.self, forKey: .seatHeaterRearRightBack)
		seatHeaterRight  = try? container.decode(Int.self, forKey: .seatHeaterRight)
		
		sideMirrorHeaters  = try? container.decode(Bool.self, forKey: .sideMirrorHeaters)
		steeringWheelHeater  = try? container.decode(Bool.self, forKey: .steeringWheelHeater)
{'fraction_non_alphanumeric': 0.08366565016811323, 'fraction_numerical': 0.0029713034639143013, 'mean_word_length': 4.543996532293021, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5869315', 'n_tokens_mistral': 4771, 'n_tokens_neox': 3975, 'n_words': 899}