Skip to content

Commit

Permalink
Merge pull request #68 from lucadjc/master
Browse files Browse the repository at this point in the history
New Samsung certificate, Fixed TemperatureConverter and added additional properties
  • Loading branch information
atxbyea authored May 21, 2023
2 parents 1e2f841 + 240080b commit 86ac05c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

.DS_Store
*.pyc
/.vs
/custom_components/climate_ip/ac14k_m.pem
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Bag Attributes
friendlyName: ac14k_m
localKeyID: 54 69 6D 65 20 31 34 35 35 34 39 32 33 35 32 36 39 36
localKeyID: 54 69 6D 65 20 31 36 37 39 37 34 37 31 35 34 30 39 37
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDeXvhcsqRFWfQt
Expand Down Expand Up @@ -32,9 +32,9 @@ NTANFxBk7alY0G7ZUhuzWkg6
-----END PRIVATE KEY-----
Bag Attributes
friendlyName: ac14k_m
localKeyID: 54 69 6D 65 20 31 34 35 35 34 39 32 33 35 32 36 39 36
subject=/C=KR/O=Samsung Electronics/CN=AC14K_M/emailAddress=AC14K_M@samsung.com
issuer=/C=KR/O=Samsung Electronics/CN=RemoteAccessCA(CE)
localKeyID: 54 69 6D 65 20 31 36 37 39 37 34 37 31 35 34 30 39 37
subject=C = KR, O = Samsung Electronics, CN = AC14K_M, emailAddress = AC14K_M@samsung.com
issuer=C = KR, O = Samsung Electronics, CN = RemoteAccessCA(CE)
-----BEGIN CERTIFICATE-----
MIIDmzCCAoOgAwIBAgIBCTANBgkqhkiG9w0BAQUFADBIMQswCQYDVQQGEwJLUjEc
MBoGA1UECgwTU2Ftc3VuZyBFbGVjdHJvbmljczEbMBkGA1UEAwwSUmVtb3RlQWNj
Expand All @@ -59,8 +59,8 @@ OCgygA+hmnBVnRDA8Jzu
-----END CERTIFICATE-----
Bag Attributes
friendlyName: CN=RemoteAccessCA(CE),O=Samsung Electronics,C=KR
subject=/C=KR/O=Samsung Electronics/CN=RemoteAccessCA(CE)
issuer=/C=KR/O=Samsung Electronics/CN=CECA
subject=C = KR, O = Samsung Electronics, CN = RemoteAccessCA(CE)
issuer=C = KR, O = Samsung Electronics, CN = CECA
-----BEGIN CERTIFICATE-----
MIIDUTCCAjmgAwIBAgIBADANBgkqhkiG9w0BAQUFADA6MQswCQYDVQQGEwJLUjEc
MBoGA1UECgwTU2Ftc3VuZyBFbGVjdHJvbmljczENMAsGA1UEAwwEQ0VDQTAiGA8x
Expand All @@ -83,8 +83,8 @@ NPCCEpp9rsIieZ58jsnc506Uc+1Vp+NmBI2A/ecypZxSb6v9gg==
-----END CERTIFICATE-----
Bag Attributes
friendlyName: CN=CECA,O=Samsung Electronics,C=KR
subject=/C=KR/O=Samsung Electronics/CN=CECA
issuer=/C=KR/O=Samsung Electronics/CN=ROOTCA
subject=C = KR, O = Samsung Electronics, CN = CECA
issuer=C = KR, O = Samsung Electronics, CN = ROOTCA
-----BEGIN CERTIFICATE-----
MIIDRTCCAi2gAwIBAgIBBDANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJLUjEc
MBoGA1UECgwTU2Ftc3VuZyBFbGVjdHJvbmljczEPMA0GA1UEAwwGUk9PVENBMCIY
Expand All @@ -107,8 +107,8 @@ nXrSOPSkcIgvS6WYw2Rii+e6lfVzqmhAmg==
-----END CERTIFICATE-----
Bag Attributes
friendlyName: CN=ROOTCA,O=Samsung Electronics,C=KR
subject=/C=KR/O=Samsung Electronics/CN=ROOTCA
issuer=/C=KR/O=Samsung Electronics/CN=ROOTCA
subject=C = KR, O = Samsung Electronics, CN = ROOTCA
issuer=C = KR, O = Samsung Electronics, CN = ROOTCA
-----BEGIN CERTIFICATE-----
MIIDRzCCAi+gAwIBAgIBADANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJLUjEc
MBoGA1UECgwTU2Ftc3VuZyBFbGVjdHJvbmljczEPMA0GA1UEAwwGUk9PVENBMCIY
Expand All @@ -128,4 +128,4 @@ zM2eoDVfS49+i/cwoi/A7fcZmIYggZho2UJR/GvKc79g6EAhT7/i5alBZF0enMsA
9okzakb/aohQE9SzsEHnhVKpGAjvu0/TJK9WwX6mkiIEJY+mzQMWgEeQt6WWIgAb
gSX9NueH80tpZ9KqFnqnOoLxTAa7k0RPBRwyUO9CDhSnlWIEcsD9sqR2M+niOFnT
KBHcLDDiEU3llprD8FRV3unYrl0F0B2GGdRk
-----END CERTIFICATE-----
-----END CERTIFICATE-----
27 changes: 14 additions & 13 deletions custom_components/climate_ip/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
DOMAIN,
HVAC_MODE_OFF,
ClimateEntity,
HVAC_MODE_OFF,
)
from homeassistant.components.climate.const import (
ATTR_MAX_TEMP,
Expand All @@ -48,16 +48,18 @@
CONF_TOKEN,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
STATE_UNKNOWN,
STATE_UNAVAILABLE,
)
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.helpers.service import extract_entity_ids
#from homeassistant.util.temperature import convert as convert_temperature
from homeassistant.util.unit_conversion import TemperatureConverter


from .controller import ATTR_POWER, ClimateController, create_controller
from .yaml_const import (
CONF_CERT,
Expand Down Expand Up @@ -111,12 +113,13 @@
vol.Optional(
CONFIG_DEVICE_UPDATE_DELAY, default=DEFAULT_UPDATE_DELAY
): cv.string,
vol.Optional(CONF_DEVICE_ID, default="032000000"): cv.string,
vol.Optional(CONF_DEVICE_ID, default='032000000'): cv.string,
}
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):

_LOGGER.setLevel(logging.INFO if config.get("debug", False) else logging.ERROR)
_LOGGER.info("climate_ip: async setup platform")

Expand All @@ -127,7 +130,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
except Exception as e:
_LOGGER.error("climate_ip: error while creating controller!")
import traceback

_LOGGER.error(traceback.format_exc())
_LOGGER.error(e)
raise
Expand Down Expand Up @@ -189,6 +191,8 @@ class ClimateIP(ClimateEntity):
def __init__(self, rac_controller, config):
self.rac = rac_controller
self._name = config.get(CONFIG_DEVICE_NAME, None)
_LOGGER.info("self._name: {}".format(self._name))

self._poll = None
self._unique_id = None
str_poll = config.get(CONFIG_DEVICE_POLL, "")
Expand All @@ -203,6 +207,8 @@ def __init__(self, rac_controller, config):
if f in self.rac.operations:
features |= SUPPORTED_FEATURES_MAP[f]
for f in SUPPORTED_FEATURES_MAP.keys():
_LOGGER.info("Feature: {}".format(f))

if f in self.rac.attributes:
features |= SUPPORTED_FEATURES_MAP[f]
self._supported_features = features
Expand Down Expand Up @@ -247,7 +253,7 @@ def unique_id(self):
if self._unique_id is None and self.rac.unique_id is not None:
_LOGGER.info("About to set unique id {}".format(self.rac.unique_id))
self._unique_id = "climate_ip_" + self.rac.unique_id

_LOGGER.info("Returning unique id of {}".format(self._unique_id))
return self._unique_id

Expand All @@ -262,8 +268,8 @@ def name(self):

@property
def state_attributes(self):
_LOGGER.info("state_attributes")
attrs = self.rac.state_attributes
_LOGGER.info("state_attributes: {0}".format(attrs))
attrs.update(super(ClimateIP, self).state_attributes)
if self._name is not None:
attrs[ATTR_NAME] = self._name
Expand Down Expand Up @@ -300,12 +306,7 @@ def target_temperature_low(self):

@property
def hvac_mode(self):
return (
HVAC_MODE_OFF
if self.rac.get_property(ATTR_HVAC_MODE)
in [STATE_UNKNOWN, STATE_UNAVAILABLE, ""]
else self.rac.get_property(ATTR_HVAC_MODE)
)
return HVAC_MODE_OFF if self.rac.get_property(ATTR_HVAC_MODE) in [STATE_UNKNOWN, STATE_UNAVAILABLE, ''] else self.rac.get_property(ATTR_HVAC_MODE)

@property
def hvac_modes(self):
Expand Down
14 changes: 5 additions & 9 deletions custom_components/climate_ip/connection_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import json
import logging
import os
import ssl
import time
import traceback
import ssl

from homeassistant.const import CONF_IP_ADDRESS, CONF_MAC, CONF_PORT, CONF_TOKEN
from requests.adapters import HTTPAdapter
from homeassistant.const import CONF_IP_ADDRESS, CONF_MAC, CONF_PORT, CONF_TOKEN

from .connection import Connection, register_connection
from .yaml_const import (
Expand All @@ -20,7 +20,6 @@
CONNECTION_TYPE_REQUEST = "request"
CONNECTION_TYPE_REQUEST_PRINT = "request_print"


class SamsungHTTPAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -31,7 +30,6 @@ def init_poolmanager(self, *args, **kwargs):
kwargs["ssl_context"] = ssl_context
return super().init_poolmanager(*args, **kwargs)


class ConnectionRequestBase(Connection):
def __init__(self, hass_config, logger):
super(ConnectionRequestBase, self).__init__(hass_config, logger)
Expand All @@ -41,7 +39,7 @@ def __init__(self, hass_config, logger):
self.update_configuration_from_hass(hass_config)
self._condition_template = None
self._thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=1)

def __del__(self):
self._thread_pool.shutdown(wait=False)

Expand Down Expand Up @@ -119,7 +117,7 @@ def execute_internal(self, template, value, device_state) -> (json, bool, int):
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
with requests.sessions.Session() as session:
self.logger.info("Setting up HTTP Adapter and ssl context")
session.mount("https://", SamsungHTTPAdapter())
session.mount('https://', SamsungHTTPAdapter())
self.logger.info(self._params)

try:
Expand All @@ -133,9 +131,7 @@ def execute_internal(self, template, value, device_state) -> (json, bool, int):
try:
resp = future.result()
except:
self.logger.error(
"Request result exception: {}".format(future.exception())
)
self.logger.error("Request result exception: {}".format(future.exception()))
return (None, False, 0)

self.logger.info(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/climate_ip/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def service_schema_map(self):

@property
def operations(self):
"""Return a list of available operations"""
""" Return a list of available operations """
return []

@property
def attributes(self):
"""Return a list of available attributes"""
""" Return a list of available attributes """
return []


Expand Down
Loading

0 comments on commit 86ac05c

Please sign in to comment.