Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hakana committed Jun 4, 2022
1 parent 31f97e5 commit d69ea05
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
27 changes: 18 additions & 9 deletions custom_components/shelly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import asyncio
import voluptuous as vol
from awesomeversion import AwesomeVersion

if os.getenv("SHELLY_DEBUGPY"):
import debugpy
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/shelly/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.climate import ClimateEntity
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
PRECISION_TENTHS,
TEMP_CELSIUS
)
try:
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/shelly/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/shelly/manifest.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
12 changes: 7 additions & 5 deletions custom_components/shelly/ws_handler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand All @@ -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":
Expand All @@ -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] = \
Expand Down

0 comments on commit d69ea05

Please sign in to comment.