Skip to content

Commit 37d2edb

Browse files
committed
feat: remove update routine for 1.2.4->1.3.0
1 parent dafc1a2 commit 37d2edb

2 files changed

Lines changed: 0 additions & 84 deletions

File tree

custom_components/sleep_as_android/__init__.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry, registry: er)
4343
except KeyError:
4444
self._name = 'SleepAsAndroid'
4545

46-
try:
47-
_tt = self._config_entry.options['topic_template']
48-
self._updating = False
49-
except KeyError:
50-
self._updating = True
51-
5246
# will call async_setup_entry from sensor.py
5347
self.hass.loop.create_task(self.hass.config_entries.async_forward_entry_setup(self._config_entry, 'sensor'))
5448
# ToDo prepare topic_template and other variables that should be defined one time.
@@ -216,47 +210,3 @@ def get_sensor(self, sensor_name: str) -> (SleepAsAndroidSensor, bool):
216210
new_sensor = SleepAsAndroidSensor(self.hass, self._config_entry, sensor_name)
217211
self.__sensors[sensor_name] = new_sensor
218212
return new_sensor, True
219-
220-
@property
221-
def updating(self) -> bool:
222-
return self._updating
223-
224-
def self_update(self):
225-
"""
226-
Run updating routine
227-
"""
228-
old_options = self._config_entry.options
229-
_LOGGER.debug(f"old options is {old_options}")
230-
try:
231-
new_options = {
232-
'name': old_options['name'],
233-
'qos': old_options['qos']
234-
}
235-
except KeyError:
236-
_LOGGER.debug("old options was not found. Will use defaults")
237-
new_options = {
238-
'name': self._name,
239-
'qos': 0,
240-
}
241-
try:
242-
topic = old_options['root_topic']
243-
new_topic = topic + "/" + DEVICE_MACRO
244-
_LOGGER.info(f"Found root_topic {topic} from v1.2.4. Will replace it by {new_topic}")
245-
except KeyError:
246-
_LOGGER.info(f"root_topic for v1.2.4 not found. Will try 'topic' from v1.1.0")
247-
try:
248-
topic = old_options['topic'] # full topic for message. Should cut after last /
249-
new_topic = '/'.join(topic.split('/')[:-1]) + "/" + DEVICE_MACRO
250-
_LOGGER.info(f"Found topic '{topic}' from v1.1.0. Will replace it by {new_topic}")
251-
except KeyError:
252-
new_topic = self.configured_topic
253-
_LOGGER.info(f"No topic information from previous versions found. Will use {new_topic}")
254-
255-
new_options['topic_template'] = new_topic
256-
_LOGGER.info("Updating...")
257-
self.hass.config_entries.async_update_entry(
258-
self._config_entry,
259-
options=new_options
260-
)
261-
_LOGGER.info("Done!")
262-
self._updating = False

custom_components/sleep_as_android/sensor.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,15 @@ async def add_configured_entities():
3434
for entity in entities:
3535

3636
device_name = instance.device_name_from_entity_id(entity.unique_id)
37-
# If we in update mode, then remove instance_name prefix from device name
38-
if instance.updating:
39-
_LOGGER.info(f"We in updating mode. Removing prefix {instance.name} for {device_name}")
40-
device_name = device_name.removeprefix(instance.name+"_")
41-
instance.entity_registry.async_update_entity(
42-
entity_id=entity.entity_id,
43-
new_unique_id=instance.create_entity_id(device_name)
44-
)
4537
_LOGGER.debug(f"add_configured_entities: creating sensor with name {device_name}")
4638
(sensor, _) = instance.get_sensor(device_name)
47-
if instance.updating:
48-
await sensor.device_update()
4939
sensors.append(sensor)
5040

5141
async_add_entities(sensors)
5242

5343
instance: SleepAsAndroidInstance = hass.data[DOMAIN][config_entry.entry_id]
5444
await add_configured_entities()
5545
_LOGGER.debug("async_setup_entry: adding configured entities is finished.")
56-
57-
if instance.updating:
58-
_LOGGER.debug("We need update. Running self_update")
59-
instance.self_update()
60-
6146
_LOGGER.debug("Going to subscribe to root topic.")
6247
await instance.subscribe_root_topic(async_add_entities)
6348
_LOGGER.debug("async_setup_entry is finished")
@@ -163,22 +148,3 @@ def device_info(self):
163148
info = {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name, "manufacturer": "SleepAsAndroid",
164149
"type": None, "model": "MQTT"}
165150
return info
166-
167-
async def device_update(self) -> None:
168-
if not self._instance.updating:
169-
return
170-
171-
device_registry = await dr.async_get_registry(self.hass)
172-
# Instance in updating mode. Device should be update too
173-
_LOGGER.info("Updating device identifiers")
174-
# v1.2.4 -> v1.2.5 update
175-
old_identifiers = {(DOMAIN, self._instance.name + "_" + self.unique_id)}
176-
_LOGGER.info(f"Trying to get v1.2.4 device {old_identifiers}")
177-
device = device_registry.async_get_device(identifiers=old_identifiers, connections=set())
178-
if device is not None:
179-
_LOGGER.info(f"Found device {device.id} from v1.2.4. Updating ... ")
180-
device_registry.async_update_device(
181-
device_id=device.id,
182-
new_identifiers=self.device_info['identifiers']
183-
)
184-
_LOGGER.info("Device updating finished")

0 commit comments

Comments
 (0)