diff --git a/custom_components/shelly/__init__.py b/custom_components/shelly/__init__.py index f04a4c9..c92dbb3 100755 --- a/custom_components/shelly/__init__.py +++ b/custom_components/shelly/__init__.py @@ -13,6 +13,7 @@ import logging import asyncio import voluptuous as vol +from awesomeversion import AwesomeVersion if os.getenv("SHELLY_DEBUGPY"): import debugpy @@ -23,7 +24,8 @@ from homeassistant.const import ( CONF_DEVICES, CONF_DISCOVERY, CONF_ID, CONF_PASSWORD, - CONF_SCAN_INTERVAL, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP) + CONF_SCAN_INTERVAL, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP, + __version__ as HAVERSION ) from homeassistant import config_entries from homeassistant.helpers import discovery from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -59,7 +61,7 @@ _LOGGER = logging.getLogger(__name__) -__version__ = "1.0.0-b2" +__version__ = "1.0.0" VERSION = __version__ async def async_setup(hass, config): @@ -80,7 +82,7 @@ async def async_setup_entry(hass, config_entry): _LOGGER.info("Starting shelly, %s", __version__) if not DOMAIN in hass.data: - hass.data[DOMAIN] = {} + hass.data[DOMAIN] = ShellyApp(hass) if config_entry.source == "import": if config_entry.options: #config.yaml @@ -107,26 +109,33 @@ async def async_setup_entry(hass, config_entry): if conf.get(CONF_UPTIME_SENSOR) and SENSOR_UPTIME not in conf[CONF_SENSORS]: conf[CONF_SENSORS].append(SENSOR_UPTIME) - hass.data[DOMAIN][config_entry.entry_id] = \ + hass.data[DOMAIN].instances[config_entry.entry_id] = \ ShellyInstance(hass, config_entry, conf) return True async def async_unload_entry(hass, config_entry): """Unload a config entry.""" - instance = hass.data[DOMAIN][config_entry.entry_id] + instance = hass.data[DOMAIN].instances[config_entry.entry_id] await instance.stop() await instance.clean() return True async def async_remove_config_entry_device(hass, config_entry, device_entry): - instance = hass.data[DOMAIN][config_entry.entry_id] - return True - + instance = hass.data[DOMAIN].instances[config_entry.entry_id] + return True +class ShellyApp(): + def __init__(self, hass): + self.hass = hass + self.instances = {} + self.ha_version = AwesomeVersion(HAVERSION) + def is_ver(self, ver): + return self.ha_version >= AwesomeVersion(ver) + class ShellyInstance(): """Config instance of Shelly""" def __init__(self, hass, config_entry, conf): - self.hass = hass + self.hass = hass self.cancel_update_listener = config_entry.add_update_listener(self.update_listener) self.config_entry = config_entry self.entry_id = self.config_entry.entry_id diff --git a/custom_components/shelly/climate.py b/custom_components/shelly/climate.py index 4384403..1805898 100644 --- a/custom_components/shelly/climate.py +++ b/custom_components/shelly/climate.py @@ -10,7 +10,7 @@ from homeassistant.components.climate import ClimateEntity from homeassistant.const import ( ATTR_TEMPERATURE, - PRECISION_WHOLE, + PRECISION_TENTHS, TEMP_CELSIUS ) try: @@ -54,7 +54,7 @@ class ShellyClimate(ShellyDevice, ClimateEntity): _attr_max_temp = 30 _attr_min_temp = 5 _attr_supported_features = FEATURES - _attr_target_temperature_step = PRECISION_WHOLE + _attr_target_temperature_step = PRECISION_TENTHS _attr_temperature_unit = TEMP_CELSIUS """Representation of an Shelly Switch.""" diff --git a/custom_components/shelly/config_flow.py b/custom_components/shelly/config_flow.py index 67ed697..de007de 100644 --- a/custom_components/shelly/config_flow.py +++ b/custom_components/shelly/config_flow.py @@ -87,7 +87,7 @@ async def async_step_init(self, user_input=None): async def async_step_user(self, user_input=None): """Handle a flow initialized by the user.""" - self.instance = self.hass.data[DOMAIN][self.config_entry.entry_id] + self.instance = self.hass.data[DOMAIN].instances[self.config_entry.entry_id] if self.instance.config_entry.source == "import" \ and not self.instance.config_entry.options: diff --git a/custom_components/shelly/manifest.json b/custom_components/shelly/manifest.json index 1c5323a..252fc0c 100644 --- a/custom_components/shelly/manifest.json +++ b/custom_components/shelly/manifest.json @@ -1,7 +1,7 @@ { "domain": "shelly", "name": "Shelly smart home", - "version": "1.0.0-b2", + "version": "1.0.0", "config_flow": true, "documentation": "https://github.com/StyraHem/ShellyForHASS/blob/master/README.md", "dependencies": ["zeroconf"], diff --git a/custom_components/shelly/ws_handler.py b/custom_components/shelly/ws_handler.py index 43bfe9c..43cdb86 100644 --- a/custom_components/shelly/ws_handler.py +++ b/custom_components/shelly/ws_handler.py @@ -1,6 +1,7 @@ """WebSocket for Shelly.""" # pylint: disable=unused-argument # from typing_extensions import Required +from distutils.log import debug import os import voluptuous as vol from homeassistant.components import websocket_api @@ -22,18 +23,19 @@ async def setup_ws(instance): @websocket_api.async_response @websocket_api.websocket_command({vol.Required("type"): "s4h/get_config", vol.Required("language"): cv.string}) async def shelly_get_config(hass, connection, msg): + app = hass.data[DOMAIN] resources = await async_get_translations( hass, msg["language"], 'frontend', - 'shelly' + {'shelly'} if app.is_ver('2022.6.0') else 'shelly' ) #print("GET CONFIG*****************") """Handle get config command.""" content = {} content["type"] = 's4h/get_config' #Debug instances = [] - for entity_id, instance in hass.data[DOMAIN].items(): + for entity_id, instance in app.instances.items(): options = {} options['yaml'] = instance.config_entry.source and not instance.config_entry.options options['name'] = instance.config_entry.title @@ -121,7 +123,7 @@ async def shelly_setting(hass, connection, msg): """Handle set setting config command.""" data = msg['data'] instance_id = data['instanceid'] - instance = hass.data[DOMAIN][instance_id] + instance = hass.data[DOMAIN].instances[instance_id] param = data['param'] id = data['id'] value = data['value'] @@ -147,7 +149,7 @@ async def shelly_config(hass, connection, msg): """Handle set setting config command.""" data = msg['data'] instance_id = data['instanceid'] - instance = hass.data[DOMAIN][instance_id] + instance = hass.data[DOMAIN].instances[instance_id] id = data['id'] cfg = ALL_CONFIG[id] if cfg.get('type')=="bool": @@ -169,7 +171,7 @@ async def shelly_convert(hass, connection, msg): "Convert config.yaml to integration" data = msg['data'] instance_id = data['instanceid'] - instance = hass.data[DOMAIN][instance_id] + instance = hass.data[DOMAIN].instances[instance_id] system_options = instance.conf.copy() data = {} data[CONF_OBJECT_ID_PREFIX] = \