{"action":"opened","issue":{"url":"https://api.github.com/repos/partofthething/infopanel/issues/12","repository_url":"https://api.github.com/repos/partofthething/infopanel","labels_url":"https://api.github.com/repos/partofthething/infopanel/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/partofthething/infopanel/issues/12/comments","events_url":"https://api.github.com/repos/partofthething/infopanel/issues/12/events","html_url":"https://github.com/partofthething/infopanel/issues/12","id":391389414,"node_id":"MDU6SXNzdWUzOTEzODk0MTQ=","number":12,"title":"Color is not pickup from config file","user":{"login":"trlafleur","id":4571691,"node_id":"MDQ6VXNlcjQ1NzE2OTE=","avatar_url":"https://avatars0.githubusercontent.com/u/4571691?v=4","gravatar_id":"","url":"https://api.github.com/users/trlafleur","html_url":"https://github.com/trlafleur","followers_url":"https://api.github.com/users/trlafleur/followers","following_url":"https://api.github.com/users/trlafleur/following{/other_user}","gists_url":"https://api.github.com/users/trlafleur/gists{/gist_id}","starred_url":"https://api.github.com/users/trlafleur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trlafleur/subscriptions","organizations_url":"https://api.github.com/users/trlafleur/orgs","repos_url":"https://api.github.com/users/trlafleur/repos","events_url":"https://api.github.com/users/trlafleur/events{/privacy}","received_events_url":"https://api.github.com/users/trlafleur/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-15T15:54:48Z","updated_at":"2018-12-15T15:54:48Z","closed_at":null,"author_association":"NONE","body":"I did a new version of your DynamicFancyText sprite that allows the color to be in the config file...\r\nit also builds this format:  label-data-units  -->  CO2: 234.2 ppm, all in one sprite\r\n\r\nWhat happens is the color is set to the defaults from class Sprite, and it stays that way until I send an MQTT data value then it changes to the colors from the config file...  what am I doing wrong???\r\n\r\nIf I remove in update_value, the         if val != self.last_val:,  statement, it work correct...\r\n\r\nI've also notice that fancytext may have the same issue, it only uses the default color\r\nis there a way to force the color change on setup??\r\nthanks.....\r\n\r\n~~~\r\n# ************************************************************** #\r\n# ************************************************************** #       \r\nclass DynamicText(FancyText):  # pylint:disable=too-many-instance-attributes\r\n    \"\"\"\r\n    FancyText that can have a changing/live data source. With Data_label, then data, then text\r\n\r\n    This has a ``label`` configuration to render something like:\r\n    ``Label: [value]``\r\n    \"\"\"\r\n\r\n    CONF = FancyText.CONF.extend({'label': vol.Coerce(str),\r\n                                  vol.Optional('data_label'): vol.Coerce(str),\r\n                                  vol.Optional('label_fmt', default='{}'): str,\r\n                                  vol.Optional('val_fmt', default='{}'): str,\r\n                                  vol.Optional('units', default=''): str })\r\n\r\n    def __init__(self, max_x, max_y, data_source):\r\n        \"\"\"Construct a sprite.\"\"\"\r\n        FancyText.__init__(self, max_x, max_y, data_source=data_source)\r\n        self.last_val = None\r\n        self.label = None\r\n        self.value = None\r\n        self.label_fmt = None\r\n        self.val_fmt = None\r\n        self.data_label = None\r\n        self.pallete = None # {'label':[0, 255, 255], 'units':[255, 0, 0], 'text': [255, 255, 255]}\r\n        self.units = None\r\n       \r\n    def apply_config(self, conf):\r\n        \"\"\"Validate and apply configuration to this sprite.\"\"\"\r\n        conf = FancyText.apply_config(self, conf)\r\n        if conf['data_label']:\r\n            # make this a callable function to enable live/updating data\r\n            self.value = lambda: self._convert_data(self.data_source[conf['data_label']])\r\n        self._make_text()\r\n        return conf\r\n\r\n    def _convert_data(self, val):  # pylint: disable=no-self-use\r\n        return val\r\n\r\n    def _make_text(self):\r\n        \"\"\"Render the label and live value.\"\"\"\r\n        if self.label:\r\n            DynamicText.add(self, self.label_fmt.format(self.label), self.pallete['text'])        # <--------------\r\n           \r\n        val = self.value() if callable(self.value) else self.value  # pylint: disable=not-callable\r\n        text = self.val_fmt.format(val)\r\n        self.last_val = val\r\n        DynamicText.add(self, text, self.pallete['label'])\r\n       \r\n        if self.units:\r\n            DynamicText.add(self, self.units, self.pallete['units'])\r\n\r\n    def update_value(self):\r\n        \"\"\"Update, but only if the value has changed.\"\"\"\r\n        val = self.value() if callable(self.value) else self.value  # pylint: disable=not-callable\r\n        if val != self.last_val:\r\n            # only do lookup when things change for speed.\r\n            self.clear()\r\n            self._make_text()\r\n\r\n    def render(self, display):\r\n        \"\"\"Render a frame and advance.\"\"\"\r\n        self.update_value()\r\n        return FancyText.render(self, display)\r\n\r\n# ************************************************************** #\r\n\r\n~~~"}}
{"actor":{"display_login":"trlafleur"}}