def test_URL_DE(self): gh = Geizhals("https://geizhals.de/apple-iphone-x-64gb-grau-a1688629.html", "DE") device = gh.parse() # avoid banning from website sleep(uniform(1, 10)) self.assertEqual(device.name, "Apple iPhone X 64GB grau")
def test_URL_UK(self): gh = Geizhals("https://cenowarka.pl/apple-iphone-x-64gb-szary-a1688629.html", "UK") device = gh.parse() # avoid banning from website sleep(uniform(1, 10)) self.assertEqual(device.name, "Apple iPhone X 64GB grey")
def test_ID_PL(self): gh = Geizhals(1688629, "PL") device = gh.parse() # avoid banning from website sleep(uniform(1, 10)) self.assertEqual(device.name, "Apple iPhone X 64GB szary")
class Geizwatch(Entity): """Implementation of Geizwatch.""" def __init__(self, name, description, product_id, domain): """Initialize the sensor.""" from geizhals import Device, Geizhals # internal self._name = name self._geizhals = Geizhals(product_id, domain) self._device = Device() # external self.description = description self.product_id = product_id @property def name(self): """Return the name of the sensor.""" return self._name @property def icon(self): """Return the icon for the frontend.""" return ICON @property def state(self): """Return the best price of the selected product.""" if not self._device.prices: return None return self._device.prices[0] @property def device_state_attributes(self): """Return the state attributes.""" while len(self._device.prices) < 4: self._device.prices.append('None') attrs = { 'device_name': self._device.name, 'description': self.description, 'unit_of_measurement': self._device.price_currency, 'product_id': self.product_id, 'price1': self._device.prices[0], 'price2': self._device.prices[1], 'price3': self._device.prices[2], 'price4': self._device.prices[3] } return attrs @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Get the latest price from geizhals and updates the state.""" self._device = self._geizhals.parse()
class Geizwatch(Entity): """Implementation of Geizwatch.""" def __init__(self, name, description, product_id, domain): """Initialize the sensor.""" from geizhals import Device, Geizhals # internal self._name = name self._geizhals = Geizhals(product_id, domain) self._device = Device() # external self.description = description self.product_id = product_id @property def name(self): """Return the name of the sensor.""" return self._name @property def icon(self): """Return the icon for the frontend.""" return ICON @property def state(self): """Return the best price of the selected product.""" if not self._device.prices: return None return self._device.prices[0] @property def device_state_attributes(self): """Return the state attributes.""" while len(self._device.prices) < 4: self._device.prices.append('None') attrs = {'device_name': self._device.name, 'description': self.description, 'unit_of_measurement': self._device.price_currency, 'product_id': self.product_id, 'price1': self._device.prices[0], 'price2': self._device.prices[1], 'price3': self._device.prices[2], 'price4': self._device.prices[3]} return attrs @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Get the latest price from geizhals and updates the state.""" self._device = self._geizhals.parse()